[Haskell-cafe] I'm trying to design a GUI library -- a design question
Ömer Sinan Ağacan
omeragacan at gmail.com
Mon Mar 3 07:50:19 UTC 2014
Hi Daniel,
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?
---
Ömer Sinan Ağacan
http://osa1.net
2014-03-02 23:38 GMT+02:00 Daniel Trstenjak <daniel.trstenjak at gmail.com>:
>
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list