[Haskell-beginners] Why the compiler does not commit to a type class?

Alexander Chen alexander at chenjia.nl
Fri Apr 17 19:56:16 UTC 2020


Prelude> u = undefined
Prelude> k :: (Ord a, Num b) => a -> b -> a; k = u

Prelude> :t k 1 2 
k 1 2 :: (Ord a, Num a) => a

Prelude> :t k (1 :: Integer) 2
k (1 :: Integer) 2 :: Integer

In the first version the compiler is not really pushed so it simply gives back the type class constriction it has to adhere to. While in the second it is pushed to give an more specific answer and thus the :: Integer.

Is this train of thought correct? 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200417/0b0ea624/attachment.html>

More information about the Beginners mailing list