[Haskell-cafe] elementary Maybe Monad problem .. sigh
Galchin, Vasili
vigalchin at gmail.com
Thu May 1 21:18:43 EDT 2008
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 ........
_ -> .........
??
Thanks, V.
On Thu, May 1, 2008 at 7:50 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> 2008/5/2 Galchin, Vasili <vigalchin at gmail.com>:
> >
> > data Bozo =
> > Bozo {
> > id :: Int
> > }
> >
> > bonzo :: Maybe Bozo -> IO ()
> > bonzo maybe_bozo = do
> > if maybe_bozo == (Just (Bozo x))
> > then
> > return ()
> > else
> > return ()
>
> bonzo maybe_bozo =
> case maybe_bozo of
> Just (Bozo x) -> return ()
> _ -> return ()
>
> Or equivalently:
>
> bonzo (Just (Bozo x)) = return ()
> bonzo _ = return ()
>
> You should watch out for your use of id as a field name, since id is a
> builtin function and you will get ambiguity errors.
>
> Luke
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080501/d727c001/attachment.htm
More information about the Haskell-Cafe
mailing list