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. Re:  IO loops with tail call (edgar klerks)
   2.  [Solved] Re: State Monads (and OpenGL) (Tom Hobbs)
   3. Re:  [Solved] Re: State Monads (and OpenGL) (Lyndon Maydwell)


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

Message: 1
Date: Mon, 8 Nov 2010 11:21:41 +0100
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] IO loops with tail call
To: Yasuyuki Ogawa <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi Yasuyuki,

Here is some resource Brent produced, why tail-recursion isn't that
important in haskell:

http://www.haskell.org/pipermail/haskell-cafe/2009-March/058607.html
(http://www.haskell.org/haskellwiki/Tail_recursion)

I think it is nice to have some background (and it is pretty interesting).

Greets,

Edgar

On Sun, Nov 7, 2010 at 4:16 AM, Yasuyuki Ogawa <[email protected]>wrote:

> Hi Brent,
>
>
> (2010/11/07 4:26), Brent Yorgey wrote:
>
>> However, the real answer is: don't worry about it!  Because of
>> Haskell's lazy evaluation, the notion of "tail call" is not very
>> important. And even if it were, you still shouldn't worry about it:
>> just write your Haskell programs in the most natural, beautiful style
>> you can think of.  Maybe at some point down the road you will have
>> to start worrying about optimization.  But you should put it off as
>> long as possible.
>>
>
> Thank you for your helpful advice. In fact, I was wondering
> how coding styles affect optimization! I'll forget it a while.
>
> --------------------------------------
> Get the new Internet Explorer 8 optimized for Yahoo! JAPAN
> http://pr.mail.yahoo.co.jp/ie8/
> _______________________________________________
> 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/20101108/e5de08e2/attachment-0001.html

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

Message: 2
Date: Mon, 8 Nov 2010 12:07:39 +0000
From: Tom Hobbs <[email protected]>
Subject: [Haskell-beginners] [Solved] Re: State Monads (and OpenGL)
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

In case anyone else happens across this and wonders the same as me.  I
got this working by using IORef.  Like so;

main = do
    world <- sequence (take (worldSize * worldSize) $ repeat rand)
    worldM <- newIORef world
    -- snip more code
   displayCallback $= (display worldM)
    idleCallback $= Just (evolveM worldM)
    -- snip yet more code

evolveM ior_world = do
    world <- readIORef ior_world
    let evolved = evolve world
    writeIORef ior_world evolved
    postRedisplay Nothing

Here, every time the idleCallback is called the world is evolved.
Since the displayCallback also has a reference (is that an acceptable
term?) to (IORef world) it can draw the latest evolved world.

On Fri, Nov 5, 2010 at 3:55 PM, Tom Hobbs <[email protected]> wrote:
> Hi all,
>
> I have a program which implements Conway's Game Of Life.  It even has
> an open GL UI which shockingly works.
>
> I've followed a tutorial
> (http://blog.mikael.johanssons.org/archive/2006/09/opengl-programming-in-haskell-a-tutorial-part-2/)
> which tells how to get the open GL to animate, and according to my
> sysouts, that's working to.  The problem I have comes with the fact
> that between every frame I want to evolve my world but I'm really
> struggling working out how to get the state stuff working.
>
> Here's a snippet of my main function;
>
> main = do
>        world <- sequence (take (worldSize * worldSize) $ repeat rand) --
> randomly generate a square world
>        -- code snipped out
>        displayCallback $= (display position world)  -- display method which
> is called on every frame redraw
>        mainLoop
>
> Here, world is a [Int] and represents my cells.  The display function
> as referenced by "displayCallback" is the function that is called back
> to everytime the frame is redrawn.
>
> I also have another function which takes in a world, updates the state
> of the cells and the evolved world, thus;
>
> evolve :: [Int] -> [Int]
>
> I've been reading through (a lot of) tutorials on the state monad but
> I'm not any closer to working out how I make the call to display take
> some kind of updated world.
>
> I've also got the following code;
>
> type World = State [Int]
>
> evolveS :: World [Int]
> evolveS = do
>              w <- get
>              let w2 = evolve w
>              put w2
>              return w2
>
> Which I believe to be the correct code for wrapping my [Int] in the
> state monad but now I have two problems;
>
> 1) I don't know if it's correct
> 2) I don't know how to apply it, even if it is
>
> Can anyone offer any advice?
>
> Many thanks,
>
> Tom
>


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

Message: 3
Date: Tue, 9 Nov 2010 00:19:40 +0800
From: Lyndon Maydwell <[email protected]>
Subject: Re: [Haskell-beginners] [Solved] Re: State Monads (and
        OpenGL)
To: Tom Hobbs <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

The IORef method is the technique I used to solve this same problem,
but I'd be interested to see if there was a nice solution involving
the state monad.

On Mon, Nov 8, 2010 at 8:07 PM, Tom Hobbs <[email protected]> wrote:
> In case anyone else happens across this and wonders the same as me.  I
> got this working by using IORef.  Like so;
>
> main = do
>    world <- sequence (take (worldSize * worldSize) $ repeat rand)
>    worldM <- newIORef world
>    -- snip more code
>   displayCallback $= (display worldM)
>    idleCallback $= Just (evolveM worldM)
>    -- snip yet more code
>
> evolveM ior_world = do
>    world <- readIORef ior_world
>    let evolved = evolve world
>    writeIORef ior_world evolved
>    postRedisplay Nothing
>
> Here, every time the idleCallback is called the world is evolved.
> Since the displayCallback also has a reference (is that an acceptable
> term?) to (IORef world) it can draw the latest evolved world.
>
> On Fri, Nov 5, 2010 at 3:55 PM, Tom Hobbs <[email protected]> wrote:
>> Hi all,
>>
>> I have a program which implements Conway's Game Of Life.  It even has
>> an open GL UI which shockingly works.
>>
>> I've followed a tutorial
>> (http://blog.mikael.johanssons.org/archive/2006/09/opengl-programming-in-haskell-a-tutorial-part-2/)
>> which tells how to get the open GL to animate, and according to my
>> sysouts, that's working to.  The problem I have comes with the fact
>> that between every frame I want to evolve my world but I'm really
>> struggling working out how to get the state stuff working.
>>
>> Here's a snippet of my main function;
>>
>> main = do
>>        world <- sequence (take (worldSize * worldSize) $ repeat rand) --
>> randomly generate a square world
>>        -- code snipped out
>>        displayCallback $= (display position world)  -- display method 
>> which
>> is called on every frame redraw
>>        mainLoop
>>
>> Here, world is a [Int] and represents my cells.  The display function
>> as referenced by "displayCallback" is the function that is called back
>> to everytime the frame is redrawn.
>>
>> I also have another function which takes in a world, updates the state
>> of the cells and the evolved world, thus;
>>
>> evolve :: [Int] -> [Int]
>>
>> I've been reading through (a lot of) tutorials on the state monad but
>> I'm not any closer to working out how I make the call to display take
>> some kind of updated world.
>>
>> I've also got the following code;
>>
>> type World = State [Int]
>>
>> evolveS :: World [Int]
>> evolveS = do
>>              w <- get
>>              let w2 = evolve w
>>              put w2
>>              return w2
>>
>> Which I believe to be the correct code for wrapping my [Int] in the
>> state monad but now I have two problems;
>>
>> 1) I don't know if it's correct
>> 2) I don't know how to apply it, even if it is
>>
>> Can anyone offer any advice?
>>
>> Many thanks,
>>
>> Tom
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


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

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


End of Beginners Digest, Vol 29, Issue 10
*****************************************

Reply via email to