On Wed, Apr 22, 2015 at 11:38 AM, Shishir Srivastava <shishir.srivastava@gmail.com> wrote:
My next question was how do i only get "34" or "3" i.e. the Maybe value without wrapped in to a 'Maybe' ?

"do" syntax lets you temporarily "unwrap" the value, but it must be rewrapped later. And if the specific monad in question is not IO, you cannot do I/O (e.g. "print" the value as in your initial message). This reflects the mapping of "do" to uses of (>>=)

    Prelude> :t (>>=)
    (>>=) :: Monad m => m a -> (a -> m b) -> m b

In this example, `m` is Maybe.

As it turns out, Maybe is one of the monads that lets you use pattern matching to extract values. Not all monads do; you cannot do this with IO, for example. The `maybe` function is often used instead of explicit pattern matching.

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net