Question

How can I make my GHCI prototyping more robust? I am locked inside IO monad just because I read my data from a file. It is a bit frustrating having to stitch liftM every time.

λ: let q xml = fmap (filterChildrenName f) $ elChildren xml
λ: liftM q xml
[[Element {elName = QName {qName = "link", qURI = Nothing, qPrefix = Nothing}, elAttribs = [], elContent = [Text (CData {cdVerbatim = CDataText, cdData = "http://planet.haskell.org/", cdLine = Nothing})], elLine = Nothing}]]
λ
Was it helpful?

Solution

Since gchi is in IO, you can use <- instead of let to bind variables

xml <- loadFromFile
q xml

OTHER TIPS

The main disadvantage of let and <- is that you lose all bindings after reloading. To use permanent bindings in the source file, you can also use unsafePerformIO :: IO a -> a from System.IO.Unsafe. It's highly indesirable in the production code (only when you are really know what you do — some low-level optimization and hackery, for example), but quite acceptable during the prototyping.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top