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:45

>>2

Yes, I forgot =, it's onWndClick ev = do ...

Thanks for pointing out the need of StateT, found this
http://www.haskell.org/haskellwiki/Simple_StateT_use
I'll take a look at it now and see if it clears out some things for me.

Something else that puzzles me are parameters of state type constructor.


newtype State s a = State (s -> (a, s))


So if I want to keep a list of Points, what should s be? a is obviously [Point].


type PtListState = State ? [Point]

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