[Haskell-cafe] Trapped by the Monads

Mark Carter mcturra2000 at yahoo.co.uk
Tue Sep 20 11:18:29 EDT 2005

I'm puzzling out how to get a Bool from am IO Bool. I know I'm not 
supposed to, but I don't see any way around my predicament.

The basic setup is: I have an edit box, and a panel. If you click the 
LMB on the panel when the edit box is checked, this means you want to 
move a graphical object around the panel. If it is unchecked, then 
clicking the LMB means you want to add a graphical object.

The relevant bits I've managed to put together so far are:

mainFrame = do -- main application frame
    streams <- varCreate []
    cbEdit <- checkBox p1 [text := "Edit Mode",  on command ::=  
onCbEdit textlog] -- p1 is the panel, ignore textlog
    let isEditing =  get cbEdit checked -- returns type IO Bool
    windowOnMouse p False {- no motion events -} (onMouse p streams  
    onMouse w streams isEditChecked mouse       
        = case mouse of
            MouseLeftDown pt mods  ->
                if isEditChecked then
                    findStream w streams pt
                    addStream w streams pt
            other                  -> skipCurrentEvent      -- 
unprocessed event: send up the window chain

             -- define findStream and addStream

The problem is that isEditChecked is of type IO Bool, not Bool. I 
presume that I should actually be taking a different (non-imperative) 
approach, and I'm wondering if anyone could suggest what that approach 
should be? Many apologies for being a clueless n00b.

Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

More information about the Haskell-Cafe mailing list