<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div>I found the handling of (IO t) by the interpreter (GHCI in my case) to be somewhat confusing.&nbsp; As pointed out below, I can type:<br><br>&nbsp;&nbsp;&nbsp; readFile "bla"&nbsp; ::&nbsp; IO String<br><br>and GHCI happily displays the contents of the file.&nbsp; However neither of the following work<br><br>&nbsp;&nbsp;&nbsp; print $ readFile "bla"<br>&nbsp;&nbsp;&nbsp; putStr $ readFile "bla"<br><br>In other words, GHCI seems perfectly willing to "unwrap" a type (IO t) and display it (assuming Show t).&nbsp; 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).<br><br>&nbsp;&nbsp;&nbsp; content &lt;- readFile "bla"<br>&nbsp;&nbsp;&nbsp; print content<br>&nbsp;&nbsp;&nbsp; putStr content<br><br>Terry<br></div><div
 style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Maria Boghiu &lt;maria.boghiu@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> haskell-cafe@haskell.org<br><b><span style="font-weight: bold;">Sent:</span></b> Monday, October 5, 2009 6:48:56 AM<br><b><span style="font-weight: bold;">Subject:</span></b> [Haskell-cafe] I/O Haskell question<br></font><br>
Hey.<br><br>I'm trying to configure Xmonad, the window manager.<br><br>for this purpose, I'm trying to read the <b>workspaces</b> variable in the code below from file.<br>As you can see, I do workspaces = readWS where<br>

<b><br>readWS = do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l &lt;- readFile "~/bla"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return l</b><br><br>I get an error saying I am mismatching types IO [String] and [String].<br>But I thought that once one does <b> l &lt;- readFile "~/bla"</b>, 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])<br>

<br><br><br>
</div></div></div></body></html>