Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Game of Life try (???????? ???????)
   2. Re:  Game of Life try (Mateusz Kowalczyk)
   3. Re:  Game of Life try (Darren Grant)
   4. Re:  Game of Life try (KC)


----------------------------------------------------------------------

Message: 1
Date: Fri, 4 Jan 2013 22:41:36 +0200
From: ???????? ??????? <[email protected]>
Subject: [Haskell-beginners] Game of Life try
To: [email protected]
Message-ID:
        <CANUoYf2tESAKByVu=5qb9nv5-mzcbcaray-c4ggt1oap4n3...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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
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! :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130104/c61c2c14/attachment-0001.htm>

------------------------------

Message: 2
Date: Fri, 04 Jan 2013 23:21:23 +0000
From: Mateusz Kowalczyk <[email protected]>
Subject: Re: [Haskell-beginners] Game of Life try
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"


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
> [email protected]
> 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-0001.htm>

------------------------------

Message: 3
Date: Fri, 4 Jan 2013 16:25:20 -0800
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] Game of Life try
To: Mateusz Kowalczyk <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <ca+jd6sj0bg6ta_cdwok8ssjcgmqxz_3_1x930e1mvgsamif...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1251"

If I may, as I'm sure many wizened functional programmers predicted, I
found that my built-in biases regarding how a computer language works were
a major hindrance to picking up Haskell quickly as they prevented me from
reading and writing it effectively. My colleagues think of mathy Haskell
guys as an odd breed. :)

Don't despair. Give yourself ample time with structured books like Learn
You a Haskell for the fundamentals to make sense. More specifically, I have
found that understanding Haskell's type system inside and out has been
critical to my effectiveness.

Cheers,
d



On Fri, Jan 4, 2013 at 3:21 PM, Mateusz Kowalczyk
<[email protected]>wrote:

>
>  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
> 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 
> [email protected]http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130104/c85ca6de/attachment-0001.htm>

------------------------------

Message: 4
Date: Fri, 4 Jan 2013 23:27:09 -0800
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] Game of Life try
To: ???????? ??????? <[email protected]>
Cc: [email protected]
Message-ID:
        <CAMLKXy=GvWLvrcrG3Zx7i8+JvvkKj=gteom+hmf-irgo+lm...@mail.gmail.com>
Content-Type: text/plain; charset=windows-1251

You might want to look at the chapter on Sudoku (and the whole book)
in "Pearls of Functional Algorithm Design" by Richard Bird.


On Fri, Jan 4, 2013 at 12:41 PM, ???????? ???????
<[email protected]> 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
> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
--
Regards,
KC



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 55, Issue 4
****************************************

Reply via email to