[Haskell-cafe] I/O Haskell question
tdchayes at pacbell.net
Mon Oct 5 17:45:23 EDT 2009
I found the handling of (IO t) by the interpreter (GHCI in my case) to be somewhat confusing. As pointed out below, I can type:
readFile "bla" :: IO String
and GHCI happily displays the contents of the file. However neither of the following work
print $ readFile "bla"
putStr $ readFile "bla"
In other words, GHCI seems perfectly willing to "unwrap" a type (IO t) and display it (assuming Show t). This bit of helpfulness may just confuse us novice users by allowing us to stray from the correct way to deal with wrapped types (monads).
content <- readFile "bla"
From: Maria Boghiu <maria.boghiu at gmail.com>
To: haskell-cafe at haskell.org
Sent: Monday, October 5, 2009 6:48:56 AM
Subject: [Haskell-cafe] I/O Haskell question
I'm trying to configure Xmonad, the window manager.
for this purpose, I'm trying to read the workspaces variable in the code below from file.
As you can see, I do workspaces = readWS where
readWS = do
l <- readFile "~/bla"
I get an error saying I am mismatching types IO [String] and [String].
But I thought that once one does l <- readFile "~/bla", l is the a string or, in this case, a String list. If I run that line in prelude it seems to be working fine, prints the content of the file "~/bla" on screen (though I'm not sure if as a String or as a list of Strings, i.e. [String])
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe