|
A conditional statement in Haskell whose right-hand side will only be evaluated if the guard statement evaluates to true. A list of guard statements are normally evaluated in a top to bottom order.
f x
| x > 0 = 1
| otherwise = 0
The guard statements occur after each "|" and before the "=".
Similar to the mathematic notation:
<math>
f(x) = \left\{ \begin{matrix}
1 & \mbox{if } x>0 \\
0 & \mbox{otherwise}
\end{matrix}
\right.
<math>
In this case the guard conditions are the "if" and "otherwise" statements.
|