Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell state

Name: Anonymous 2010-04-25 15:36

I've been learning Haskell for more than a month now and I did not have too much trouble understanding monads in general, but the state monad is giving me a headache. I think I have a vague idea how it works, but I am still unable to do the following:



data Point = Point {
    ptX :: Float,
    ptY :: Float }

main = do
    -- create window and register some event handlers
    mainGUI

onWndClick ev do
    let x = eventX ev
    let y = eventY ev
    -- put this point into list

onPaint canvas = do
    -- draw the points from the list


How the hell do I update a list of points in click event handler and draw those points in onPaint? My every attempt failed either with compiler errors or list not updating.

Name: Anonymous 2010-04-25 16:51

>>3
No, s is the type of your state, so it should be [Point]. a is the type returned from an expression after the state is evaluated, and if you don't want to return a value you use () just like you'd do with IO.

You might want to take a look at how State is implemented, to understand better what it actually does.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List