Haskell IF statements -
i'm pretty new haskell, if make if statement:
function b c | (a+b == 0) = true | --etc. | otherwise = false is second if statement same else if in other languages, or if. assume former can have 1 output, want make sure.
the construct used called guard. haskell checks given alternatives 1 after until 1 condition yields true. evaluates right hand side of equation.
you pretty write
function n | n == 1 = ... | n == 2 = ... | n >= 3 = ... thus guard kinds of represents if/elseif construct other languages. otherwise defined true, last
| otherwise = will true , therefore represents catch-all else clause.
nontheless, haskell has usual a = if foo 23 else 42 statement.
Comments
Post a Comment