by yiransheng · 8y ago · 0 comments
fn :: Maybe Int -> Maybe Int -> Int
fn q z = fromMaybe 0 $
do
q_in <- q
z_in <- z
return (q_in + z_in) fromMaybe 0 $
(+) <$> xm <*> ym fn (Just q) (Just z) = q + z
fn _ _ = 0 fn = liftM2 (+)You're missing the point entirely.
> the original example gets rid of the Maybe, defaulting to 0.
http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-M...
fn x y = case (x, y) of
(Just q, Just z) -> q + z
(_, _) -> 0
but the case becomes implicit in the repetition of the function name at the top level of indentation.At the same level, really - it works in a let or a where as well.