[Haskell-cafe] Polymorphic addition function with variable number of arguments?

Some One haskellie at gmail.com
Tue Mar 13 18:29:32 CET 2012

Dear Haskellers,

I'm trying to define a polymorphic "add" function which takes a variable
number of arguments (instance of Num) and returns their sum. I don't want
to specify the types of the arguments while calling the function, I just
want to , at most, specify the return type (*it should infer that the
return type is the type of the arguments*).

class Add a b where
    add :: a -> b

instance Num a => Add a a where
    add = id

instance (Num a, Add a b) => Add (a -> b) where
    add x y = add (x + y)

Can someone tell me why this is not working and propose a fix for this, if

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120313/0a1f393c/attachment.htm>

More information about the Haskell-Cafe mailing list