
Yes, an if statement must have both 'then' and 'else' branches. As an
example, what if you had
let a = if b == 2 then True else False
and you were missing an else branch? What would 'a' get assigned to?
The if statement "returns" a value so must have both branches.
However, in a monadic constraint, there are the functions 'when' and
'unless.' They allow conditional evaluation of expressions in a monadic
context. For example,
main = do
line <- getLine
when (line == "hello") putStrLn "Hello back!"
Cheers,
- Tim
On Wed, Oct 21, 2009 at 7:43 PM, michael rice
It looks like both the THEN and the ELSE in an IF expression must each have an expression. What's a graceful way to do nothing in either or both slots, kind of like the Fortran CONTINUE statement.
--mr
================
[michael@localhost ~]$ ghci GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude> if (1==1) then else
<interactive>:1:15: parse error on input `else' Prelude> if (1==1) then True else
<interactive>:1:24: parse error (possibly incorrect indentation) Prelude> if (1==1) then True else False True Prelude>
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe