tags:

views:

90

answers:

1

I'm writing Haskell, but this could be applied to any OO or functional language with a concept of ADT. I'll give the template in Haskell, ignoring the fact that the arithmetic operators are already taken:

class Thing a where
   (+) :: a -> a -> a
   (-) :: a -> a -> a
   x - y = x + negate y
   (*) :: (RealFrac b) => a -> b -> a
   negate :: a -> a
   negate x = x * (-1)

Basically these are things that can be added and subtracted and also multiplied by real fractional values. One example might be a simple list of numbers: addition and subtraction are pairwise (in Haskell, "(+) = zipWith (+)"), and multiplication by a real multiplies every item in the list by the same amount. I've come across enough other examples to want to define it as a class, but I don't know exactly what to call it.

In Haskell its usually a monoid provided there is some kind of zero value.

Is this some known kind of object in the zoo of algebraic types? I've looked through rings, semirings, nearsemirings, groups etc without finding it.

+8  A: 

This is a vector space: http://en.wikipedia.org/wiki/Vector_space. You have addition and scalar multiplication.

sclv
also, if Haskell is the language you're coding for (and you don't mind use of language extensions) there's a nice library on Hackage called "vector-space" that already has a class for this.
mokus
Thanks. Thats what I want. And thanks mokus for pointing me at the package.
Paul Johnson
There is a good hierarchy of algebra structures in http://hackage.haskell.org/package/numeric-prelude
Daniel Velkov
Yes, I looked through the Numeric Prelude. Then I looked at the Standard Prelude until my head stopped spinning. Much as I find the standard Prelude constraining, especially when trying to define something like "instance Num VectorSpace", I still prefer it to encyclopaedic complexity of the Numeric Prelude.
Paul Johnson