next up previous
Next: Let Expressions Up: Expressions Previous: Lambda Expressions, Applications and

Conditionals

You can write if-then-else statements that evaluate to values as in

if 1 > 0 then 1 else 0 end;
which evaluates to 1. The ``then'' and ``else'' parts of the statement must have the same types and the ``if'' part must be a boolean expression. Thus, the following produce type errors:
if 1 then 1 else 0 end;
if 1 < 0 then 1 else "oops" end;
It is important to remember that, if-statements evaluate to values (kind of like the a ? b : c syntax in C). So for example, the following is perfectly legal:
"ccl is " <> ( if true 
                 then "strange but beautiful" 
                 else "just strange" 
               end );
which you can probably evaluate in your head.



Eric Klavins 2003-12-03