wxHaskell: convenience functions

I'm experimenting with wxHaskell, and I've got something like: main = run mainFrame mainFrame = do -- main application frame ... cbEdit <- checkBox p1 [text := "Edit Mode", on command ::= onCbEdit textlog] ... where ... It would be useful to have some convenience function, let's say, isEditing, which works out whether cbEdit is checked, or not. That way, one could just pass this in as a parameter without requiring any extra code. The problem is, I can't see how it can be done. I've tried various things in the main section, and nothing worked. I tried putting the following defintion into the where clause: isEditing = do checkedp <- get cbEdit checked return checkedp but the compiler complained that cbEdit is not in scope. I /could/ pass in cbEdit as a parameter to isEditing, but I'd rather not. ___________________________________________________________ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

Actually, I can see how my requirement of not wanting to pass in cbEdit might not be so good. From an FP point of view, that's just asking for trouble. A better solution would appear to be to put the cbEdit in as a parameter, and just face the fact that all callers will be required to pass an extra parameter. Mark Carter wrote:
I'm experimenting with wxHaskell, and I've got something like:
main = run mainFrame
mainFrame = do -- main application frame ... cbEdit <- checkBox p1 [text := "Edit Mode", on command ::= onCbEdit textlog] ... where ...
It would be useful to have some convenience function, let's say, isEditing, which works out whether cbEdit is checked, or not. That way, one could just pass this in as a parameter without requiring any extra code. The problem is, I can't see how it can be done. I've tried various things in the main section, and nothing worked. I tried putting the following defintion into the where clause:
isEditing = do checkedp <- get cbEdit checked return checkedp
but the compiler complained that cbEdit is not in scope. I /could/ pass in cbEdit as a parameter to isEditing, but I'd rather not.
___________________________________________________________ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
___________________________________________________________ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

On Fri, Sep 16, 2005 at 06:30:54PM +0100, Mark Carter wrote:
Actually, I can see how my requirement of not wanting to pass in cbEdit might not be so good. From an FP point of view, that's just asking for trouble. A better solution would appear to be to put the cbEdit in as a parameter, and just face the fact that all callers will be required to pass an extra parameter.
It depends on where you want this convenience function to be visible. You could define mainFrame = do ... cbEdit <- checkBox p1 [text := "Ed... let isEditing = get cbEdit checked ... and you're perfectly fine. The catch is that isEditing is now only visible in this scope. You could pass isEditing to another function without causing any trouble. It might be cleaner than passing cbEdit around (for example, if the mechanism by which the "isEditing" state is stored ever changes). -- David Roundy
participants (2)
-
David Roundy
-
Mark Carter