[Haskell-cafe] elementary Maybe Monad problem .. sigh

Galchin, Vasili vigalchin at gmail.com
Thu May 1 21:27:21 EDT 2008


Here is a simpler case of what I want to do ..

1) To function1 pass in (Maybe Int).

2) If "Nothing" then pass nullPtr to C function.

3) If "Just 1", then pass a pointer to a "1" to teh same C function.

Thanks, Vasili


On Thu, May 1, 2008 at 8:18 PM, Galchin, Vasili <vigalchin at gmail.com> wrote:

> 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/f10b6a6e/attachment.htm


More information about the Haskell-Cafe mailing list