[Haskell-cafe] Using catch and errors

robert dockins robdockins at fastmail.fm
Fri Apr 22 12:32:46 EDT 2005

> Now I have one problem (Well 2 really but the second one is just me not
> having programmed in haskell for so long that I forgot). getLine is used for
> the sole purpous of stopping the program and allowing the user to read the
> error message before the window closes but error does not allow me to do
> that and aparently using a lambda function (As shown below) does not work
> (It gives error upon compilation
>  when ((length keyno /= 1) && (keyno /= "1") && (keyno /= "0")) (\_ ->
> putStrLn "Please input either 0 or 1 as key number"
> getLine
> exitWith ExitSuccess)
> So is there anyway to fix that?

You need a "do" not a lambda ( or use >> )

when (stuff) (do putStrLn "blah"
                  exitWith ExitSuccess)


when (stuff) (putStrLn "blah" >> getLine >> exitWith ExitSuccess)

> The second error is that apparenlty (keyno /= "1") and (keyno /= "0") do not
> work, but I suspect that, like Java, one can't compare strings using = sign
> or am I wrong?

No, that should work.  Haskell equality is not at all like Java 
equality.  In java, '=' basicaly means pointer equality.  I am not aware 
of a way to even make that comparison in Haskell (in general).  Haskell 
'=' behaves a lot more like equals() in Java.

Remove the length test and I think your condition will do what you expect.

More information about the Haskell-Cafe mailing list