Conditional expressions

Aconditional expressionhas the formif c then t else f,wherecis an expression of typeBoolean,andtandfare expressions of any type, buttandfmust have the same type.

Evaluation of conditional expressions is non-strict. The evaluation semantics ofif c then t else fare:

  • The conditioncis always evaluated.
  • Ifcevaluates totrue,the expressiontis evaluated andfremains unevaluated. The whole expression reduces to the value oft.
  • Ifcevaluates tofalse,the expressionfis evaluated andtremains unevaluated. The whole expression reduces to the value off.

The keywordsif,then,andelseeach introduce ablockas follows:

if
    true
  then
    "codeblock here"
  else
    "another codeblock"