how to write an interactive program ? gui library to use ?
Hi all, 1/ I'd like to know how can I implement an interactive program (an editor) in haskell where some "things" have to be updated. The "things" can be text in a word processor, or a pixel array in a 2d graphics editor, and so on. Have I to pass the state (the "things") explicitely in the arguments of the main loop (a recursive function) ? Sorry if it's stupid... 2/ Another one concerning gui library: what's the best choice ? I need it to work both on linux and windows. I also need it can handle an OpenGL context. thanks a lot, minh thu
On Fri, 2006-02-24 at 19:31 +0100, minh thu wrote:
Hi all,
1/ I'd like to know how can I implement an interactive program (an editor) in haskell where some "things" have to be updated. The "things" can be text in a word processor, or a pixel array in a 2d graphics editor, and so on. Have I to pass the state (the "things") explicitely in the arguments of the main loop (a recursive function) ? Sorry if it's stupid...
2/ Another one concerning gui library: what's the best choice ? I need it to work both on linux and windows. I also need it can handle an OpenGL context.
There are two Haskell GUI libs that fit those requirements: Gtk2Hs and wxHaskell. http://haskell.org/gtk2hs/ http://wxhaskell.sourceforge.net/ Duncan
At 7:31 PM +0100 2/24/06, minh thu wrote:
Hi all,
1/ I'd like to know how can I implement an interactive program (an editor) in haskell where some "things" have to be updated. The "things" can be text in a word processor, or a pixel array in a 2d graphics editor, and so on. Have I to pass the state (the "things") explicitely in the arguments of the main loop (a recursive function) ? Sorry if it's stupid...
No, it's not a stupid question at all... Essentially, the answer is "yes", the state needs to be passed around (neglecting hackery to simulate global variables that is better avoided). However, this can be made convenient by using a monad. You define a monad which is based on IO and carries your state (something like StateT YourState IO a; see http://www.haskell.org/ghc/docs/latest/html/libraries/mtl/Control-Monad-Stat...).
Dean Herington wrote:
At 7:31 PM +0100 2/24/06, minh thu wrote:
Hi all,
1/ I'd like to know how can I implement an interactive program (an editor) in haskell where some "things" have to be updated. The "things" can be text in a word processor, or a pixel array in a 2d graphics editor, and so on. Have I to pass the state (the "things") explicitely in the arguments of the main loop (a recursive function) ? Sorry if it's stupid...
No, it's not a stupid question at all...
Essentially, the answer is "yes", the state needs to be passed around (neglecting hackery to simulate global variables that is better avoided). However, this can be made convenient by using a monad. You define a monad which is based on IO and carries your state (something like StateT YourState IO a; see http://www.haskell.org/ghc/docs/latest/html/libraries/mtl/Control-Monad-Stat...).
If the things need to be more explicitly mutable you can *) Create a bunch of IORefs (or MVar for thread safety) *) Put them into some data structure (your own or perhaps tuples) *) Use a ReaderT from Control.Monad.Reader, ReaderT YourData IO a Then you can *) lookup the IORef you need with using "asks" *) read/write/update that mutable data
participants (4)
-
Chris Kuklewicz -
Dean Herington -
Duncan Coutts -
minh thu