Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. type inference: how ghc chooses e.g. between Float and
Double? (TP)
2. Re: type inference: how ghc chooses e.g. between Float and
Double? (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Fri, 07 Jun 2013 12:42:57 +0200
From: TP <[email protected]>
Subject: [Haskell-beginners] type inference: how ghc chooses e.g.
between Float and Double?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="ISO-8859-1"
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
------------------------------
Message: 2
Date: Fri, 7 Jun 2013 09:19:17 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] type inference: how ghc chooses e.g.
between Float and Double?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAN+Tr41AM=h_cy0afgfm9e_3rv7x2vnky3y3y9ht7ofu1em...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
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 <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 60, Issue 13
*****************************************