[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] powering of new types

Subject: Re: [Haskell-cafe] powering of new types
From: Jochem Berndsen
Date: Tue, 22 Dec 2009 19:13:33 +0100
slemi wrote:
> oh well thats pretty straight-forward:)
> 
> the next thing i don't understand is how ghci turns 1 into (Scalar 1).
> 1 == (Scalar 1) returns True, which is logical in a way (NOT), but if i
> change the type definition to
> data Matrix a = Matr {unMatr :: [[a]]} | Lol a | Scalar a
> then
> 1 == (Scalar 1) still returns True, but
> 1 == (Lol 1) returns False, no matter in what order I put them in the
> definition... o.O

Numeric literals in Haskell are overloaded. 1 really means
fromInteger 1. The function fromInteger is defined by instances of Num.
This is why you can use a numeric literal wherever your program expects
a Double, Int, Integer, and so on. This includes your own type. You have
probably defined fromInteger = Scalar for your type.

Cheers, Jochem

-- 
Jochem Berndsen | [email protected] | [email protected]çåçé.com
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>