Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1.  Why is the type constraint different from        signature?
      (Lai Boon Hui)
   2. Re:  Why is the type constraint different from    signature?
      (David McBride)


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

Message: 1
Date: Mon, 29 Aug 2016 22:56:46 +0800
From: Lai Boon Hui <laibo...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Why is the type constraint different from
        signature?
Message-ID:
        <cajdqggkdiy_r425xttnd5gygoeicp9gecogku8bpxsl3aff...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi All,

can some one explain to me why

ghci> let f:: (Ord a, Num b) => a -> b -> a ; f=undefined
ghci> :t f 1 2
ghci> f 1 2 :: (Num a, Ord a) => a

The initial type signature just required *a* to be a type that is an
instance of Ord but after it had the additional constraint of Ord as well???


-- 
Best Regards,
Boon Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160829/0741721b/attachment-0001.html>

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

Message: 2
Date: Mon, 29 Aug 2016 11:08:23 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Why is the type constraint different
        from    signature?
Message-ID:
        <CAN+Tr41Crr5Zba=58emffao5gt1bo-cgb_qpjkg0eemn6ga...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

>:t f
f :: (Num b, Ord a) => a -> b -> a

a is an instance of Ord
b is an instance of Num

>:t 1
1 :: Num a => a
>:t f 1
f 1 :: (Num a, Num b, Ord a) => b -> a

the literal 1 is an instance of Num, therefore
a must be an instance of Ord but now also of Num

What we know about a is that it must be a Num (because we assigned it the
literal 1 which is a Num) and that it must also be an Ord (because your
original type signature specified that it must also be an Ord).

On Mon, Aug 29, 2016 at 10:56 AM, Lai Boon Hui <laibo...@gmail.com> wrote:

> Hi All,
>
> can some one explain to me why
>
> ghci> let f:: (Ord a, Num b) => a -> b -> a ; f=undefined
> ghci> :t f 1 2
> ghci> f 1 2 :: (Num a, Ord a) => a
>
> The initial type signature just required *a* to be a type that is an
> instance of Ord but after it had the additional constraint of Ord as well???
>
>
> --
> Best Regards,
> Boon Hui
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160829/f17af4ca/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 98, Issue 23
*****************************************

Reply via email to