[Haskell-beginners] Game of Life try

Mateusz Kowalczyk fuuzetsu at fuuzetsu.co.uk
Sat Jan 5 00:21:23 CET 2013


I recommend that you read a guide/tutorial/book on Haskell first, before 
you try to implement this. Having a very limited knowledge about the 
language will only provide frustration when your solution doesn't work 
when you try to approach it naively, trying to use methods from a very 
different language.

A widely recommended book is Learn You A Haskell [1]. After reading it, 
it should become fairly obvious how to approach your problem as well as 
how to solve it. You'll soon realise that there's simply no need for 
things such as `while' or a mutable array.

To just hint towards what you might want is  a function that takes a 
list (or list of lists, whatever your representation may be)) and 
returns a list with the next generation. You can then use any of the 
graphics libraries (or just print ASCII) to visualise the 
transformation. Again, this will be a lot easier when you actually study 
the basic language concepts first, instead of diving head-in and trying 
to hammer C++ into Haskell.

[1] http://learnyouahaskell.com/

Mateusz Kowalczyk

Oops, forgot to CC the mailing list.
On 04/01/13 20:41, Емануела Моллова wrote:
> Hello all! :) I'm new to Haskell and I would like to try to implement 
> a simple version of Game of Life. I can imagine it in C++ for example, 
> but I have a little difficulties in Haskell. All I can think for is a 
> mutable array with all elements - 0 in the beginning and the user to 
> be able to write in the coordinates of the cells, which are alive and 
> this cells to become 1. Then to iterate through the array (but I'm not 
> sure if I can iterate, there is no 'while' here) and to make the 
> changes (but maybe I will need a new array for the changes, because 
> when the first change happens, it will affect the result). Also I was 
> thinking of how to make it visible, so I tried to make all 0-s red and 
> all 1-s green, and after each iteration to clear the screen with ANSI 
> so that it looks a bit like animation, but none of these ideas work... 
> Here is an orientation in my ideas:
>
> import Data.Array.IO <http://Data.Array.IO>
> import System.Console.ANSI
>
> main :: IO ()
> main = do
>         arr <- newArray ((1,1), (10,10)) 0 :: IO (IOArray (Int, Int) Int)
> writeAraay arr (1,1) 1
> a <- readArray (1,1)
> setSGR [SetColor Foreground Dull Red]
>         putStr [a]
>
> Could you please suggest me what is a good place to store the 
> information about my cells (mutable, unmutable array, lists, 
> tuples...) and any ideas and tutorials at all would be really 
> appreciated! Thank you very much in advance! :)
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130104/6b791891/attachment.htm>


More information about the Beginners mailing list