[Haskell-beginners] IO and ghci

Mike Houghton mike_k_houghton at yahoo.co.uk
Sun Apr 19 09:46:11 UTC 2015


Hi,

I have this in a .hs file and it works fine. That is I see lines printed to the screen when the .hs file is loaded  and run from ghci.

main = do
	file <- readFile "poem.txt"
	mapM_ putStrLn (lines file)


Experimenting at the ghci command line with

let f = readFile “poem.txt”     
the above is fine.

But doing 

lines f 

gives 
<interactive>:52:7:
    Couldn't match type ‘IO String’ with ‘[Char]’
    Expected type: String
      Actual type: IO String
    In the first argument of ‘lines’, namely ‘f’
    In the expression: lines f

In my simplistic beginners way I think this is because when I run main = do …
everything is or is within an ‘impure’ area but at ghci command line it is not and I’m mixing pure/impure functions.

So my questions are 
1. Is this simplistic view any where near correct? 
2. How can I progress at the command line in ghci?


Many thanks

Mike




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150419/309ca221/attachment.html>


More information about the Beginners mailing list