Is an alternative to Conditional Expressions, in which a sequence of logical expressions called guards is used to choose between a sequence of results of the same Type.

If the first guard is True then the first result is chosen otherwise, if the second guard is True then the second result is chosen, and so on.

The guards are syntactically defined by | and the syntax of a guarded equation is

fName | guard1          = res1
      | guard2          = res2
      | guard3          = res3
      | otherwise       = res4

Examples

abs n | n >= 0          = n
      | otherwise       = -n
 
abs -1

1