Guard_statement Guard_statement

Guard statement - Definition and Overview

Related Words: Accounting, Acquaintance, Address, Affidavit, Affirmation, Anacrusis, Announcement, Annual, Annunciation, Answer, Apostrophe, Articulation, Assertion, Assumption

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.

Copyright 2009 WordIQ.com - Privacy Policy  :: Terms of Use  :: Contact Us  :: About Us
This article is licensed under the GNU Free Documentation License. It uses material from the this Wikipedia article.