
2 Mar
2014
2 Mar
'14
4:38 p.m.
Hi Ă–mer,
In a sense I'm like trying to emulate something like closures with mutable closed-over data in impure languages.
One way is to keep the specific data completely out of the Widget and use a closure to hold the data: data Widget = Widget { handleKey :: Key -> Widget , draw :: Int -> Int -> Int -> Int -> IO () , getFocus :: Widget , loseFocus :: Widget } someWidget :: SomeWidgetData -> Widget someWidget dat = Widget { handleKey = \key -> case key of 'A' -> someWidget $ dat { ... } ; ... , draw = \x y w h -> ... , getFocus = someWidget $ dat { focus = True } , loseFocus = someWidget $ dat { focus = False } } Greetings, Daniel