<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hello haskell-cafe@<br><br></div>I'm writing a GUI app in Haskell and bindings to the widget toolkit i'm using in parallel. These bindings are very simple and all its functions have return type (IO something).<br><br></div>So far so good, i wrote the following code to create an config window:<br><br>createConfigUI root = do<br>    box <- Box.add root<br><br>    -- first field<br>    addToPackEnd box =<< do<br>        f <- Fr.add box<br>        setPartText f Nothing "E-mail"<br>        setPartContent f Nothing =<< do<br>            box <- Box.add box<br><br>            addToPackEnd box =<< do<br>                e <- Ent.add box<br>                Ent.singleLineSet e True<br>                -- Here<br>                onEvent "changed,user" e $ do<br>                     reactOnUserInput e<br>                objectShow e<br>                return e<br><br>            objectShow box<br>            return box<br><br>        objectShow f<br>        return f<br><br>    -- next field<br>    addToPackEnd box =<< do<br>        ...<br><br></div>Initially, i was quite satisfied with flipped bind use for creating UI elements and arranging them. Nested do scopes allow copypasting code without renaming variables and also provide some visual representation on widget hierarchy.<br><br>But at some point i need to return some stuff from some inner do block into outmost. For example, at the line with comment "Here" i defined<br><br></div>let setText t = entrySet e t<br><br></div>and wanted to return it from whole createConfigUI action. Moreover, createConfigUI have much more fields, for each of them i want to do the same.<br><br></div>My initial thought was to wrap everything with runWriter and just call<br><br></div>tell setText<br><br></div>wherever i want to gather all setter functions into a list, but i can't do this because i would need to put liftIO before every IO action all over the place.<br><br></div>If only there was i way to turn an (IO a) into (MonadIO m => m a), it would be easy.<br><br></div>Another solution is to make my bindings return (MonadIO m => m a). This would be equal effort of plugging liftIO's everywhere, but at least it would be hidden from user of bindings. I'd gone this way, but looked at gtk bindings first and found that (IO a) is used there.<br><br></div>So, my questions are:<br><br></div>1. What would you recommend in my situation? Is it possible yield values from inner do blocks into outer without much hassle?<br></div>2. If there is nothing wrong with switching bindings from (IO a) to MonadIO typeclass, why not to do this for gtk, wxWidgets and nearly every FFI binding?<br><br></div>Thanks in advance.<br></div>