On 26 nov 2008, at 17:18, abdullah abdul Khadir wrote:

Hi,

The function getMyLine written by me is intended for getting a complete string from the standard input.

import IO

getMyLine :: IO [Char]
getMyLine =  do
                c <- getChar
                if(c == '\n')
                        then return ""
                        else    cs <- getMyLine
                                return [c]

However I keep getting the following error:

io.hs:14:2: Parse error in pattern
Failed, modules loaded: none.

I fail to understand what the error is. I tried out various things such as changing the alignment and so on to no avail. The following program, however, compiled successfully though it has the same structure as the previous program.

The "else" should be replaced by "else do". Probably you'll also want the last line to be "return (c:cs)".

By the way, questions like these might be more appropriate on haskell- beginners or haskell-cafe.

-chris



checkd :: IO Bool
checkd = do
                c <- getChar
                if(c=='d')
                        then    return True
                        else    return False

Prelude> :load ./io.hs
[1 of 1] Compiling Main             ( io.hs, interpreted )
Ok, modules loaded: Main.
*Main> checkd
d
True

_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to