[Haskell-cafe] I'm trying to design a GUI library -- a design question

Daniel Trstenjak daniel.trstenjak at gmail.com
Mon Mar 3 08:06:46 UTC 2014

Hi Ömer,

On Mon, Mar 03, 2014 at 09:50:19AM +0200, Ömer Sinan Ağacan wrote:
> This won't work. Let's say there has been two keypresses and I called
> handleKey two times. First time it updates the `dat` and returns it
> but how can I pass that updated `dat` object to the same function in
> second invocation?

If you call 'handleKey', then it returns a new Widget with a new
'handleKey' function having a closure over the modified 'dat'.

data Counter = Counter
   { increase :: Counter
   , draw     :: IO ()

someCounter :: Int -> Counter
someCounter count = Counter
   { increase = someCounter $ count + 1
   , draw     = print count

*Main> let c = someCounter 0
*Main> draw c
*Main> let c' = increase someCounter 
*Main> draw c'


More information about the Haskell-Cafe mailing list