In ghci, if I do
Prelude> :t 5
Prelude> 5 :: Num a => a
But if I assign 5, I get Integer
as the type:
Prelude> let f = 5
Prelude> t: f
Prelude> f :: Integer
From my understanding, the fact that 5 is Num a => a
allows is to sit in any mathematical expression happily (such as 5 + 5.0
). I guess I'm curious if this is Haskell magic, or whether I can make a variable f
that behave the same way, so that I can do f + 5.0
. I've tried the following with no luck:
let f = 10 :: Num a => a
f + 5.0
still gives me an error.