I'm currently trying to develop a tiny Conway's Game of Life in Haskell. I wrote a library, lifegame, that enables to manage a grid of cells and to compute its generations (see github.com/qleguennec/lifegame.git). Generations is an infinite list. So far, the library is working great, but lacks documentation. This is a small library and it shouldn't be so hard to get in it.
Now, what I'm here for is, I'm trying to use lifegame coupled with helm to actually show generations to the screen. Here's what I wrote:
import FRP.Helm
import FRP.Helm.Graphics (Element(..))
import qualified FRP.Helm.Window as Window
import FRP.Helm.Animation (Frame, AnimationStatus(..), animate, absolute)
import FRP.Helm.Time (second, running, delta)
import FRP.Elerea.Simple
import Cell.Display (allGenFrames)
import LifeGame.Data.CellGrid (CellGrid(..), randCellGrid)
render :: Form -> (Int, Int) -> Element
render form (x, y) = collage x y $ [form]
main :: IO ()
main = do
cg <- randCellGrid 50 50
anim <- return . absolute $ allGenFrames cg (1 * second) 10
engine <- startup defaultConfig
run engine $ render <~ (animate anim running status) ~~ Window.dimensions engine
where
config = defaultConfig { windowTitle = "bats"
, windowDimensions = (500, 500)}
status = effectful $ getLine >>= \i -> return $
case i of
"Pause" -> Pause
"Stop" -> Stop
"Cycle" -> Cycle
(from: github.com/qleguennec/bats.git)
The hard work of the computation lives in animate running status
", line 20. I don't really understand what the second argument of animate is. Besides, I'm not sure that feeding an infinite list of Frames is legit.
When I launch the code, the game freezes and stops 5 min afterwards. It seems to consume all memory and crash. Now, I understand that all of this lacks documentation. I'm working on it. But, being baby Haskeller, and a baby FRP/SDL developer, I need to know if I'm doing this the wrong way (and I probably do). Any comment accepted and recommended. Thanks.