(Num t) => [t] or [Int]

View: New views
3 Messages — Rating Filter:   Alert me  

(Num t) => [t] or [Int]

by PR Stanley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
I thought [1, 2, 3] :: [Int]
GHC says it's (Num t) > [t]
Okay, when it comes to 3.3:[1,2,3] (Num t) => [t] makes more sense.
Is that the only reason?
Cheers,
Paul

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: (Num t) => [t] or [Int]

by Bulat Ziganshin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello PR,

Saturday, May 10, 2008, 1:07:48 AM, you wrote:

> Okay, when it comes to 3.3:[1,2,3] (Num t) => [t] makes more sense.
> Is that the only reason?

the reason is that 1 as any other numerical constant, may be directly
used as Int, Integer, Double or any other Num value. if 1 is Int, you
will need to make more conversions

--
Best regards,
 Bulat                            mailto:Bulat.Ziganshin@...

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: (Num t) => [t] or [Int]

by Brandon S. Allbery KF8NH :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2008 May 9, at 17:07, PR Stanley wrote:

> I thought [1, 2, 3] :: [Int]
> GHC says it's (Num t) > [t]
> Okay, when it comes to 3.3:[1,2,3] (Num t) => [t] makes more sense.  
> Is that the only reason?

The Haskell 98 standard says that numeric literals are of type Num t  
=> t (so you don't need to fromIntegral everything that looks like an  
Int but is used with e.g. Doubles).  Therefore a list of them is Num t  
=> [t].

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@...
system administrator [openafs,heimdal,too many hats] allbery@...
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe