
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