<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. As pointed out below, I can type:<br><br> readFile "bla" :: IO String<br><br>and GHCI happily displays the contents of the file. However neither of the following work<br><br> print $ readFile "bla"<br> putStr $ readFile "bla"<br><br>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).<br><br> content <- readFile "bla"<br> print content<br> 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 <maria.boghiu@gmail.com><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> l <- readFile "~/bla"<br> 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 <- 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>