Reputation: 1829
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}]]
λ
Upvotes: 3
Views: 150
Reputation: 1918
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.
Upvotes: 0
Reputation: 144136
Since gchi is in IO, you can use <-
instead of let to bind variables
xml <- loadFromFile
q xml
Upvotes: 13