[Haskell-cafe] Using catch and errors
cgibbard at gmail.com
Fri Apr 22 12:42:35 EDT 2005
On 4/22/05, robert dockins <robdockins at fastmail.fm> wrote:
> > 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.
Of course, you mean Haskell '==', as Haskell '=' is declared equality,
which is somewhat like '=' in mathematics.
> Remove the length test and I think your condition will do what you expect.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe