[Haskell-beginners] type inference: how ghc chooses e.g. between Float and Double?
TP
paratribulations at free.fr
Fri Jun 7 12:42:57 CEST 2013
Hi all,
In ghci, let us type:
> data Worker x y = Worker x y deriving Show
> let a = Worker 2 3.4
> :t a
a :: Worker Integer Double
According to which procedure does ghci chooses Integer for 2, and Double for
3.4? I believed that in such a case I was compelled to indicate a type
signature explicitly, for example:
> let a = Worker (2::Int) (3.4::Float)
> :t a
a :: Worker Int Float
I knew that numbers in Haskell are polymorphic constants instances of the
Num typeclass:
> :t 2
2 :: Num a => a
But what is happening exactly when he chooses Integer and Double above?
Thanks in advance,
TP
More information about the Beginners
mailing list