[Haskell-cafe] elementary Maybe Monad problem .. sigh
Brent Yorgey
byorgey at gmail.com
Fri May 2 11:38:06 EDT 2008
2008/5/1 Galchin, Vasili <vigalchin at gmail.com>:
> Sorry .. my example was bad. I want to use "x" .. in then branch where
> it occur ...
>
> e.g.
> bonzo :: Maybe Bozo -> IO ()
> bonzo maybe_bozo = do
> case maybe_bozo of
> Just (Bozo x) -> x ........
> _ -> .........
>
> ??
>
Sure, after pattern-matching on the x (using a case, or a top-level pattern
match), you are free to use x in the resulting branch. For example:
bonzo (Just (Bozo x)) = print (show x) >> return x -- or whatever
bonzo Nothing = return ()
-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080502/d68c8d11/attachment.htm
More information about the Haskell-Cafe
mailing list