
21 Apr
2009
21 Apr
'09
9:02 p.m.
On Tue, 2009-04-21 at 17:49 -0700, michael rice wrote:
How do I get the x out of Just x?
Michael
=============
safeDivision :: Float -> Float -> Maybe Float safeDivision x y = if y == 0 then Nothing else Just (x/y)
*Main Data.List> safeDivision 10 5 Just 2.0 *Main Data.List> 3 + (safeDivision 10 5)
This would do: case safeDivision 10 5 of Just x -> 3 + x Nothing -> Nothing The Maybe-monad might make this a bit more convenient: ghci> let plusthree a = do a' <- a; return (a'+3) ghci> plusthree (Just 5) Just 8