[Haskell-cafe] Wondering if this could be done.

Gregory Crosswhite gcross at phys.washington.edu
Mon Nov 22 02:13:41 EST 2010

On 11/21/10 10:48 PM, Magicloud Magiclouds wrote:
> Hi,
>    For example, I have a data A defined. Then I want to add (+) and (-)
> operators to it, as a sugar (compared to addA/minusA). But * or other
> stuff defined in class Num is meanless to A. So I just do:
> (+) :: A ->  A ->  A
> (+) a b =
>    A (elem1 a + elem1 b) (elem2 a + elem2 b) -- I got errors here, for
> the (+) is ambiguous.
>    So, just wondering, does this way work in Haskell?

One solution to this problem is to use slightly modified operators, such 
as ".+." and ".-.", or anything else that crosses your fancy and is 
accepted by the compiler.


More information about the Haskell-Cafe mailing list