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. Re:  Lost Monad Signature (Quentin Liu)


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

Message: 1
Date: Sat, 9 Dec 2017 16:29:13 -0500
From: Quentin Liu <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Lost Monad Signature
Message-ID: <36e26a32-8617-484e-a334-84ee582af598@Spark>
Content-Type: text/plain; charset="utf-8"

Thanks for the explanation. But why did Haskell pick up the Reader monad in 
particular? Is this part of the HM type inference rule?

Regards,
Qingbo Liu

On Dec 8, 2017, 13:12 -0500, David McBride <[email protected]>, wrote:
> If you type :i Monad in ghci, you will see this instance
>
> instance Monad ((->) r)
>
> What this means is a function where the first argument is of type 'r'... is a 
> monad.  You can in fact use do notation / return on a tuple to manipulate its 
> second argument monadically.
>
> So let's look at what that does to the type signature of join when 'm' is 
> ((->) b)
>
> join :: Monad m => m (m a) -> m a
>
>  -- m = ((->) b)
>
> join :: ((->) b ((->) b a)) -> (((->) b a))
>
> Now we just have to move the arrows from prefix to infix.  Let's do it step 
> by step.
>
> join :: ((->) b (b -> a)) -> (b -> a)
> join :: (b -> (b -> a)) -> (b -> a)
>
> x -> (y -> z) is equivalent to x -> y -> z
>
> join :: (b -> b -> a) -> (b -> a)
> join :: (b -> b -> a) -> b -> a
>
> So now when you put an operator into it that takes two arguments
>
> (,) :: a -> b -> (a,b)
>
> You get the type you saw.
>
> join (,) :: b -> (b, b)
>
>
>
>
>
> > On Fri, Dec 8, 2017 at 10:37 AM, Quentin Liu <[email protected]> 
> > wrote:
> > > Hi,
> > >
> > > The function `join` flattens a double-layered monad into one layer and 
> > > its type signature is
> > >
> > >   join :: (Monad m) => m (m a) -> m a
> > >
> > > But when the first argument supplied is `(,)`, the type signature becomes
> > >
> > >   join (,) :: b -> (b, b)
> > >
> > > in ghci. The monad constraint is lost when supplied the first argument. 
> > > So my question is why the type constraint is lost and what monad is 
> > > supplied here.
> > >
> > > Regards,
> > > Qingbo Liu
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171209/3b262b35/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 114, Issue 12
******************************************

Reply via email to