[Haskell-beginners] Why is the type constraint different from signature?
David McBride
toad3k at gmail.com
Mon Aug 29 15:08:23 UTC 2016
>: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 <laiboonh at 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 at 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.html>
More information about the Beginners
mailing list