If we type show 2
,then we will get "2".But the question is show satisfies show :: Show a => a -> String
,and 2
is polymorphic, if unfortunately show 2::Int
differs from show 2::Integer
we'd have to write show 2::Int
and show 2::Integer
rather than simply show 2
.
I refuse to assume that the compiler is enough intelligent to know when (A a)=>show a
,all current instances of A are of Show, gives the same result, we needn't to specify show a::X
and when (A a)=>show a
,all current instances of A are of Show, gives different results, we have to specify show a::X
.
This is due to defaulting rules. So show 2
is actually show (2::Integer)
. You can read this in haskell 2010 report here in section 4.3.4.
To answer your second question, compiler is not intelligent enough. It happens due to type defaulting.
You can check
number = 2
In ghci
*Main> :t number
number :: Integer
Now your custom default signature
default (Int)
number = 2
In ghci
*Main> :t number
number :: Int
You can read about when a type is defaultable in the document I referenced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With