| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NumHask.Free.Ring
Description
Free ring — the initial encoding of Ring.
Synopsis
- data Ring a
- zero :: Ring a
- one :: Ring a
- plus :: Ring a -> Ring a -> Ring a
- negate :: Ring a -> Ring a
- minus :: Ring a -> Ring a -> Ring a
- times :: Ring a -> Ring a -> Ring a
- embed :: a -> Ring a
- lift :: (Eq a, Ring a) => a -> Ring a
- normalize :: (Eq a, Ring a) => Ring a -> Ring a
- eval :: Ring a => Ring a -> a
- foldRing :: b -> b -> (b -> b -> b) -> (b -> b) -> (b -> b -> b) -> (a -> b) -> Ring a -> b
- fromAdditive :: Additive a -> Ring a
- fromMultiplicative :: Multiplicative a -> Ring a
- fromSubtractive :: Subtractive a -> Ring a
Documentation
Free ring over a carrier type.
The initial encoding of Ring.
Combines additive and multiplicative structure with the
antipode. Distributivity is enforced by eval, not by
the term structure — Times over Plus is not reduced
automatically. Use eval to project into a lawful ring.
Instances
lift :: (Eq a, Ring a) => a -> Ring a Source #
Lift a carrier value, absorbing additive and multiplicative identities.
>>>lift 0Zero>>>lift 1One
normalize :: (Eq a, Ring a) => Ring a -> Ring a Source #
Normalize a term with respect to ring laws: identity absorption and
antipode involution. Distributivity is left to eval.
>>>normalize (embed 0)Zero
eval :: Ring a => Ring a -> a Source #
Evaluate a term into any Ring.
This is the unique homomorphism out of the free ring.
foldRing :: b -> b -> (b -> b -> b) -> (b -> b) -> (b -> b -> b) -> (a -> b) -> Ring a -> b Source #
Universal property: fold with a target ring.
fromAdditive :: Additive a -> Ring a Source #
Inject an additive term into the free ring.
fromMultiplicative :: Multiplicative a -> Ring a Source #
Inject a multiplicative term into the free ring.
fromSubtractive :: Subtractive a -> Ring a Source #
Inject a subtractive term into the free ring.