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 possible?
Thanks in advance