haskell - State monad and gtk2hs -


i trying retain state on gui application may able construct list of values user input. have trouble understanding state monad so...
here test code illustrate want (it obvious not compile, haven't tryed to) :

-- // --  main :: io () main =    initgui    build <- buildernew    builderaddfromfile build "test.glade"     mainwindow <- buildergetobject build casttowindow "mainwindow"    mainwindow `ondestroy` mainquit     mquit <- buildergetobject build casttobutton "quit"    mquit `onclicked` mainquit     entry   <- buildergetobject build casttoentry "entry"    mupdate <- buildergetobject build casttobutton "update"     mupdate `onclicked`       txt <- entrygettext entry       runstate (addtolist txt) []       return ()     widgetshowall mainwindow    maingui  -- // --  addtolist :: string -> state [string] () addtolist ent = >>= \x -> put $ x ++ [ent] 

anyway think should using statet instead of state complete mess in head (have read many tutos...). if worked, not since give initial state of [] @ each loop. question how write function addtolist each time update button pressed user input added state (a list of previous input)?

first of all, state statet

type state s = statet s identity 

maybe need use statet 1 level up, this:

runstatet $ put [] lift $ mupdate `onclicked`    txt <- lift $ entrygettext entry    listwas <-      put $ txt : listwas   --in reverse order    return () 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -