[Haskell-cafe] Code walking off the right edge of the screen
Jeremy Shaw
jeremy at n-heptane.com
Sat Jun 20 15:00:11 EDT 2009
At Sat, 20 Jun 2009 20:45:16 +0200,
Stephan Friedrichs wrote:
> If it's a function, you can use guards:
>
> foo :: ...
> foo something somethingElse
> | something -> putStrLn "howdy there!"
> | somethingElse -> putStrLn "howdy ho!"
> | otherwise -> ...
You can also artificially introduce places to use gaurds inside a function:
foo =
let x | 1 > 1 = "uh-oh"
| otherwise = "all is well"
in x
bar =
case () of
_ | 1 > 1 -> "uh-oh"
| otherwise -> "all is well"
- jeremy
More information about the Haskell-Cafe
mailing list