[Haskell-cafe] wxHaskell: getting a checkbox state

Remi Turk rturk at science.uva.nl
Fri Sep 16 10:52:30 EDT 2005


On Fri, Sep 16, 2005 at 12:12:50AM +0200, Sebastian Sylvan wrote:
> On 9/14/05, Mark Carter <mcturra2000 at yahoo.co.uk> wrote:
> > The problem I was having before was that I was trying to create a
> > separate function onCbEdit, thus:
> >    cbEdit <- checkBox p1 [text := "Edit Mode", on command :=  onCbEdit
> > textlog   ]
> > This had the problem that onCbEdit basically needed to have its control
> > passed in (i.e. cbEdit) as a parameter in order to inspect its state. So
> > I wanted to do something like:
> >    cbEdit <- checkBox p1 [text := "Edit Mode", on command :=  onCbEdit
> > textlog   cbEdit ]
> > Except you can't do that, because  cbEdit isn't yet defined. But your
> > suggestion gets 'round that. In the main loop, I now do:
> >   cbEdit <- checkBox p1 [text := "Edit Mode" ]
> >   set cbEdit [ on command :=  onCbEdit textlog  cbEdit ]
> 
> Some extension (I think) to GHC allows mdo-notation (recursive do). So
> you can do this:
> mdo -- yadayada....
>        cbEdit <- checBox p1 [text := "Edit Mode", on comand :=
> onCbEdit textlog cbEdit]
>        -- yadayada...

No extensions are needed, actually:

  cbEdit <- checBox p1 [text := "Edit Mode", on comand ::= onCbEdit textlog]
                                                       ^^^
						       Note the double colon.

Prelude Graphics.UI.WX> :t (:=)
(:=) :: Attr w a -> a -> Prop w

Prelude Graphics.UI.WX> :t (::=)
(::=) :: Attr w a -> (w -> a) -> Prop w

Prelude Graphics.UI.WX> :t (:~)
(:~) :: Attr w a -> (a -> a) -> Prop w

Prelude Graphics.UI.WX> :t (::~)
(::~) :: Attr w a -> (w -> a -> a) -> Prop w

Happy hacking,
Remi

-- 
Nobody can be exactly like me. Even I have trouble doing it.


More information about the Haskell-Cafe mailing list