Read file problems

Hal Daume III hdaume at ISI.EDU
Mon Sep 15 08:19:28 EDT 2003


This is a pretty simple problem to fix.  (>>=) has type IO a -> (a -> IO
b) -> IO b.  'readFile my_file' has type IO String, so this means
whatever comes on the RHS of >>= should have type (String -> IO b).  In
your case, it doesn't.  It has type String -> [something], but the
[something] isn't an IO type.

Hint: you need to put a call to 'return' in there.

 - Hal

On Mon, 2003-09-15 at 06:55, Frederic BELLOC wrote:
> HI,
> I have a recurrent probleme with function readFile and Monad :
> it is that i try to get a line, transform it  and stock it in a list
> and what i want is that function return me the list.
> But hugs say me that in
> readFile my_file >>= \s -> map cons_line (lines s)
> readFile is a IO String type but is used here as [[Char]] type...
> and i don't know what to do... 
> Ghc say me that is the lambda abstraction that fails with 
> "map cons_line (lines s)" , he couldn't match IO against [] !
> Help me please, i understand well (i hope) how Monad work but here i don't see
> a solution.
> Sorry for my poor english but i'm already a student.
> Thanks for all.
 Hal Daume III                                   | hdaume at
 "Arrest this man, he talks in maths."           |

More information about the Haskell-Cafe mailing list