logoalt Hacker News

jvuygbbkuurxtoday at 4:12 PM1 replyview on HN

Does this solution copy the state on each iteration?


Replies

WJWtoday at 5:09 PM

Haskell values are immutable, so it creates a new state on each iteration. Since most of these "game of life" type problems need to touch every cell in the simulation multiple times anyway, building a new value is not really that much more expensive than mutating in place. The Haskell GC is heavily optimized for quickly allocating and collecting short-lived objects anyway.

But yeah, if you're looking to solve the puzzle in under a microsecond you probably want something like Rust or C and keep all the data in L1 cache like some people do. If solving it in under a millisecond is still good enough, Haskell is fine.

show 1 reply