1

Let's say I have a function ($10).

Now, since 10 is of type Num a => a, ($10) is surely of type Num a => (a -> b) -> b, and GHCi confirms this.

But when I say let f = ($10), GHC infers f's type to be (Integer -> b) -> b, as if the let-assignment deduced some 'extra' information from the use of the literal.

Does this mean GHC's type inference coerces a concrete type for literals?

But if so, why does :t ($10) return Num a => (a -> b) -> b ?

f :: Num a => (a -> b) -> b
f = ($10)

typechecks, and f (+0.1) yields a correct result, while

g = ($10)

called with g (+0.1) fails, expecting an Integer.

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
Csongor Kiss
  • 715
  • 6
  • 11

0 Answers0