Banner

Game of Life in Haskell

Posted by alpheccar - Jul 18 2007 at 20:15 CEST

WARNING : This post has no interest :-)

Initially, I wanted to connect a comonadic implementation of the game of life to OpenGL. It worked but I had a space leak (and still have). I am not good at all at finding space leaks. So, I have postponed that comonadic implementation (and perhaps will use arrows in the future).

I finally decided to be much more conservative and used a simpler solution based on unboxed arrays.

The code is attached to this post. I have not made any attempt at optimizing it and the result is totally usable.

To compile:


 ghc -o simple -O2 --make Main.hs

Then you can just launch the app and press 'q' to quit. The app is also allowing an argument between 10 and 200 to control the grid size.

Have fun !

Here is a screenshot:

image

Tags | | |

Attachments

Comments

Add a comment...

Posted by ptolomy - Jul 18 2007 at23:47 CEST

Yeah, there are ncurses bindings available, but I twiddle with haskell on 3 different machines at work and at home and I'm generally too lazy to install non-standard things, so I haven't really made use of them. At one point I tried to make a really simple-yet-high-level ANSI library for console stuff, but it went horribly wrong when I tried it on Windows.

I'm ashamed to admit it, but I am reluctant to use anything that doesn't come standard with a haskell install. The relative austerity of bundled haskell libraries is probably necessary due to the rapidity of change, but most neat projects start as little hacks that grow. Having to find and fuss with a library probably adds to the perception of haskell as impractical. The question of "is this library maintained? is this the best one? how do I install it?" is an uncomfortable one for folks used to everything they typically need coming bundled with the language. To get back on topic, I am certain that what I pasted would've been a neat ncurses-based haskell life program if the library didn't require more than one step to start using.

Cool !

Posted by alpheccar - Jul 18 2007 at23:03 CEST

Cool ! Next step : implementing a real animation in the console. Are there some Haskell bindings to ncurse ?

Posted by ptolomy - Jul 18 2007 at22:57 CEST

My version, sans GL and efficiency. :)

http://hpaste.org/1757