[Haskell-beginners] help with IO and guards

Miro Karpis miroslav.karpis at gmail.com
Sat Jun 1 02:02:40 CEST 2013


Please, I'm trying to do some user user input validation, but it looks like
my  approach is not correct. Here is my code:

textInput :: IO ()
textInput
| dataIn == "bye" = return ()
| otherwise          = textInput
where dataIn <- getLine

the idea is that when user inputs "bye" the program should end/return.
Problem is that I'm getting 'parse error on input `<-'' error. How can I
achieve it?

Another question I have is: how can I have more actions in guard, when the
condition is valid. Something like (write on IO + return if dataIn == "bye):

textInput :: IO ()
textInput
*| dataIn == "bye" = (puStrLn "quitting", return () ) -- *
| otherwise          = textInput
where dataIn <- getLine

Millions of thanks for any kind of input..

Cheers,
Miro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130601/9cf8099f/attachment.htm>


More information about the Beginners mailing list