I've done a Haskell library allowing to manipulate multivariate polynomials. It uses some instances defined by the numeric-prelude library, e.g. an additive group instance. The addition for this instance is denoted + in this library. I find this a bit annoying because there's already the usual + for numbers, so I defined:
import Algebra.Additive as AlgAdd (^+^) :: Polynomial a -> Polynomial a -> Polynomial a (^+^) p q = p AlgAdd.+ q But it seems to me that by doing that, the "infix properties" of + are lost. I never dealt with the infix properties, and I have a couple of questions. I want to keep the same infix properties.
Looking at the code I see this line:
infixl 6 +, -
This line is isolated, at the beginning of the code. So should I similarly include the line
infixl 6 ^+^, ^-^ at the beginning of my code? In this blog post the author defines the infix property of a function just before defining this function. Is it another, equivalent way to proceed? And is it not possible to do something like (^+^) = (AlgAdd.+) in such a way that the infix properties are automatically copied?
Still looking at the code, I see:
{-# MINIMAL zero, (+), ((-) | negate) #-}
What does that mean?
I'm also wondering how to define the opposite of a polynomial. I have the substraction
p ^-^ qbut how to define^-^ p?Finally, when the package author defines the instance e.g. for
Double, he/she writes:instance C Double where {-# INLINE zero #-} {-# INLINE negate #-} {-# INLINE (+) #-} {-# INLINE (-) #-} zero = P.fromInteger 0 negate = P.negate (+) = (P.+) (-) = (P.-)
What is the purpose of INLINE?