
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 0 *Main> let c' = increase someCounter *Main> draw c' 1 Greetings, Daniel