[Haskell-beginners] type inference: how ghc chooses e.g. between Float and Double?
David McBride
toad3k at gmail.com
Fri Jun 7 15:19:17 CEST 2013
The relevant section of the report:
http://www.haskell.org/onlinereport/decls.html#sect4.3.4
But basically if there is no default call in a haskell file it is
defined to be default(Integer,Double) by default.
On Fri, Jun 7, 2013 at 6:42 AM, TP <paratribulations at free.fr> wrote:
> 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
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list