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"
    print content
    putStr content

Terry




________________________________
From: Maria Boghiu <maria.bog...@gmail.com>
To: haskell-cafe@haskell.org
Sent: Monday, October 5, 2009 6:48:56 AM
Subject: [Haskell-cafe] I/O Haskell question

Hey.

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"
         return l

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])
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to