I want to take some of the templates from Num declarations for several custom classes (call them Monomial and Polynomial). Instead of writing
instance Num (Monomial) where
f - g = f + (negate g)
abs _ = undefined
Is there any way around this? I came across standard instances of the superclass and something called the strathclyde haskell extension , which, if implemented, will allow me to write something like
class SimpleNum a => Num a where
(+) :: a -> a -> a -- standard ring stuff
(*) :: a -> a -> a
one :: a
zero :: a
instance Num (SimpleNum a) where
f - g = f + (negate g)
abs _ = undefined
What is the usual / easy way to handle this?
source
share