Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  About monad (Trung Quang Nguyen)
   2. Re:  About monad (Edward Z. Yang)
   3. Re:  About monad (Tom Davie)
   4. Re:  About monad (Trung Quang Nguyen)


----------------------------------------------------------------------

Message: 1
Date: Thu, 20 Dec 2012 15:07:02 +0100
From: Trung Quang Nguyen <[email protected]>
Subject: [Haskell-beginners] About monad
To: beginners <[email protected]>
Message-ID:
        <CALs5uBy97og=dse2wFAObVCw=t8H0Xi6r985ar95Fne=fp+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi all,

I saw this


   1. instance Monad Maybe where
   2.     return x = Just x
   3.     Nothing >>= f = Nothing
   4.     Just x >>= f  = f x
   5.     fail _ = Nothing


I am wondering about the implementation of function (>>=). Why don't
it be *Just
x >>= f = Just (f x)*?

Any body knows about this?

--Trung
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121220/263cf930/attachment-0001.htm>

------------------------------

Message: 2
Date: Thu, 20 Dec 2012 22:12:02 +0800
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] About monad
To: Trung Quang Nguyen <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1356012708-sup-2809@javelin>
Content-Type: text/plain; charset=UTF-8

Excerpts from Trung Quang Nguyen's message of Thu Dec 20 22:07:02 +0800 2012:
> Hi all,
> 
> I saw this
> 
> 
>    1. instance Monad Maybe where
>    2.     return x = Just x
>    3.     Nothing >>= f = Nothing
>    4.     Just x >>= f  = f x
>    5.     fail _ = Nothing
> 
> 
> I am wondering about the implementation of function (>>=). Why don't
> it be *Just
> x >>= f = Just (f x)*?

Try it; it won't typecheck.

Cheers,
Edward



------------------------------

Message: 3
Date: Thu, 20 Dec 2012 14:13:28 +0000
From: Tom Davie <[email protected]>
Subject: Re: [Haskell-beginners] About monad
To: Trung Quang Nguyen <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"


On 20 Dec 2012, at 14:07, Trung Quang Nguyen <[email protected]> wrote:

> Hi all,
> 
> I saw this
> 
> instance Monad Maybe where  
>     return x = Just x  
>     Nothing >>= f = Nothing  
>     Just x >>= f  = f x  
>     fail _ = Nothing  
> 
> I am wondering about the implementation of function (>>=). Why don't it be 
> Just x >>= f = Just (f x)?
> 
> Any body knows about this?

The reason is in the type of bind:

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

The function f takes a non-in-a-monad value, and gives you an in-a-monad value.

Bob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121220/de0b1ecd/attachment-0001.htm>

------------------------------

Message: 4
Date: Thu, 20 Dec 2012 15:25:45 +0100
From: Trung Quang Nguyen <[email protected]>
Subject: Re: [Haskell-beginners] About monad
To: Tom Davie <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <CALs5uBxEJJxM-CEqw5RxQKjByqEgRxeDp=cqqvxhl0w8aed...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Oh yes, I understand now.

Just x >>= f  = f x
the output of f is actually (Monad value) like in this example

(Just 3) >>= (\x -> Just $ x^2)

At the first sight, I thought about (Monad (f x)), but it's wrong because
it will be (Monad (Monad value)) when f return.

Thanks a lot!

--Trung




2012/12/20 Tom Davie <[email protected]>

>
> On 20 Dec 2012, at 14:07, Trung Quang Nguyen <[email protected]> wrote:
>
> Hi all,
>
> I saw this
>
>
>    1. instance Monad Maybe where
>    2.     return x = Just x
>    3.     Nothing >>= f = Nothing
>    4.     Just x >>= f  = f x
>    5.     fail _ = Nothing
>
>
> I am wondering about the implementation of function (>>=). Why don't it be
> *Just x >>= f = Just (f x)*?
>
> Any body knows about this?
>
>
> The reason is in the type of bind:
>
> (>>=) :: Monad m => m a -> (a -> m b) -> m b
>
> The function f takes a non-in-a-monad value, and gives you an in-a-monad
> value.
>
> Bob
>
>


-- 
*Trung Nguyen*
Mobile: +45 50 11 10 63
LinkedIn: http://www.linkedin.com/pub/trung-nguyen/36/a44/187
View my blog at http://www.onextrabit.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121220/fbbf70e2/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 54, Issue 30
*****************************************

Reply via email to