Read file problems
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. -- C, socks and sun ;-) and haskell bugs :-( ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Read file problems
Hi, 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 | [EMAIL PROTECTED] "Arrest this man, he talks in maths." | www.isi.edu/~hdaume ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Read file problems
Hal Daume III <[EMAIL PROTECTED]> disait récemment : > Hi, > > 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. > Yes, thanks ps : i've read something like that in the Monad Tutorial but i was not sure... http://www.nomaware.com/monads/html/index.html -- C, socks and sun ;-) No haskell bug :-D ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe