Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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. Return function (Shishir Srivastava)
2. Re: Return function (Josh Holland)
----------------------------------------------------------------------
Message: 1
Date: Tue, 21 Apr 2015 12:16:47 +0100
From: Shishir Srivastava <[email protected]>
To: beginners <[email protected]>
Subject: [Haskell-beginners] Return function
Message-ID:
<CALe5RTvsdABKXLNPxzLzeFB1cvJJkV5XFN9wb-QpvOX=np3...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
Looking at the definition of return function for a Monad, it is described
as -
return :: a -> m a
However when I do -
return (Just 3)
The result is
Just 3
and not
Just (Just 3)
If I understand the definition correctly (which doesn't seem to be the
case) the return function should wrap the parameter (which in my case is
'Just 3') into the Maybe Monad and therefore should return me 'Just (Just
3)'
Please can someone help explain.
Thanks,
Shishir Srivastava
+44 (0) 750 127 5019
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150421/9a57f6fc/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 21 Apr 2015 12:21:30 +0100
From: Josh Holland <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Return function
Message-ID:
<[email protected]>
Content-Type: text/plain
Hi,
On Tue, 21 Apr 2015, at 12:16 PM, Shishir Srivastava wrote:
> Hi,
>
> Looking at the definition of return function for a Monad, it is described
> as -
>
> return :: a -> m a
>
> However when I do -
>
> return (Just 3)
>
> The result is
>
> Just 3
>
> and not
>
> Just (Just 3)
>
> If I understand the definition correctly (which doesn't seem to be the
> case) the return function should wrap the parameter (which in my case is
> 'Just 3') into the Maybe Monad and therefore should return me 'Just (Just
> 3)'
>
You haven't been clear about what environment you are "doing" `return
(Just 3)`. My guess is that you are running it in GHCi, which means that
it gets coerced to the IO monad. If you add an explicit type
declaration, you get the wrapping as expected:
Prelude> :t return (Just 3)
return (Just 3) :: (Num a, Monad m) => m (Maybe a)
Prelude> return (Just 3) :: Maybe (Maybe Int)
Just (Just 3)
Thanks,
Josh
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 82, Issue 26
*****************************************