typelift / Algebra

Abstract Algebraic Structures in Swift
MIT License
53 stars 10 forks source link

Semiring incorrect, needs to be re-designed #11

Open bkase opened 7 years ago

bkase commented 7 years ago

With the current definition of Semiring, that is:

protocol Semiring: Multiplicative, Additive { }

There is no notion of defining a separate plus and times, as Multiplicative and Additive both inherit from Semigroup and Magma and so only have a single <> operation defined on them.

I propose we rename Additive -> Monoid and make Multiplicative use a new operator for the times operation. We can alias <+> to <> as in the Haskell Semiring package. Since <.> can't be defined in Swift (what's used in Haskell's Semiring) and <*> is apply, maybe we use <**>?

bkase commented 7 years ago

Alternatively we can just overload + and *