SemigroupHom

Trait SemigroupHom 

Source
pub trait SemigroupHom {
    type Source: Semigroup;
    type Target: Semigroup;

    // Required method
    fn apply(&self, x: &Self::Source) -> Self::Target;
}
Expand description

A semigroup homomorphism: a structure-preserving map between semigroups that preserves combine.

A homomorphism f: S → T preserves the semigroup operation:

Laws (not enforced by type system):

  • Preserve combine: f(x.combine(y)) == f(x).combine(f(y))

§Example

use algebra::Max;
use algebra::Semigroup;
use algebra::SemigroupHom;

// A homomorphism from Max<i32> to Max<i32> that doubles the value
struct Double;

impl SemigroupHom for Double {
    type Source = Max<i32>;
    type Target = Max<i32>;

    fn apply(&self, x: &Max<i32>) -> Max<i32> {
        Max(x.0 * 2)
    }
}

// Verify: f(x ⊔ y) = f(x) ⊔ f(y)
// Since join = max: f(max(a, b)) = max(f(a), f(b))
let f = Double;
let x = Max(3);
let y = Max(5);
assert_eq!(f.apply(&x.combine(&y)), f.apply(&x).combine(&f.apply(&y)));

Required Associated Types§

Source

type Source: Semigroup

The source semigroup

Source

type Target: Semigroup

The target semigroup

Required Methods§

Source

fn apply(&self, x: &Self::Source) -> Self::Target

Apply the homomorphism

Implementors§