Type Hierarchy Reference¶
Katharos organises its types into two independent abstract hierarchies defined in katharos.algebra.
Combining Computational
--------- -------------
Semigroup[S] Functor[F, A]
| |
Monoid[M] Applicative[App, A]
|
Monad[Mon, A]
Concrete types
Maybe[A] -> Monad
Result[E, A] -> Monad
IO[A] -> Monad
ImmutableList[T] -> Monad + Monoid
NonEmptyList[T] -> Monad + Semigroup
MonoidMaybe[A] -> Monoid
Sum -> Monoid
Product -> Monoid
Combining Hierarchy¶
Semigroup[S]¶
Module: katharos.algebra.semigroup
Abstract base class for types with an associative binary operation.
op(other: S) -> SCombines this value with other. Must satisfy
(a @ b) @ c == a @ (b @ c).Exposed as the
@operator:a @ bis equivalent toa.op(b).
Monoid[M]¶
Module: katharos.algebra.monoid | Extends: Semigroup[M]
Adds an identity element to Semigroup.
identity() -> M(classmethod)Returns the identity element. Must satisfy
a @ identity() == aandidentity() @ a == afor alla.
Computational Hierarchy¶
Functor[F, A]¶
Module: katharos.algebra.functor
Abstract base class for types that support mapping a function over their contents.
Laws: x.fmap(id) == x | x.fmap(g ∘ f) == x.fmap(f).fmap(g)
fmap(f: Callable[[A], B]) -> Functor[F, B]Applies f to the value inside the functor and returns a new functor of type
B.
Applicative[App, A]¶
Module: katharos.algebra.applicative | Extends: Functor[App, A]
Adds the ability to lift plain values into the context and to apply a wrapped function to a wrapped value.
Laws:
v ** App.pure(id) == vApp.pure(x) ** App.pure(f) == App.pure(f(x))App.pure(y) ** u == u ** App.pure(lambda f: f(y))w ** (v ** (u ** App.pure(compose))) == (w ** v) ** u
pure(x: T) -> Applicative[App, T](classmethod)Lifts a plain value into the applicative context.
ap(wrapped_funcs: Applicative[App, Callable[[A], B]]) -> Applicative[App, B]Applies the function inside wrapped_funcs to the value inside this applicative.
Exposed as the
**operator:value ** wrapped_funcis equivalent tovalue.ap(wrapped_func).
Monad[Mon, A]¶
Module: katharos.algebra.monad | Extends: Applicative[Mon, A]
Adds sequencing of computations that themselves produce monadic values.
Laws:
Monad.ret(a).bind(f) == f(a)m.bind(ret) == mm.bind(f).bind(g) == m.bind(lambda x: f(x).bind(g))
ret(x: T) -> Monad[Mon, T](classmethod)Lifts a plain value into the monad. Delegates to
pure.bind(f: Callable[[A], Monad[Mon, B]]) -> Monad[Mon, B](abstract)Passes the unwrapped value to f and returns the resulting monad. Short-circuits on failure contexts (
Nothing,Failure).Exposed as the
|operator:m | fis equivalent tom.bind(f).then(other: Monad[Mon, B]) -> Monad[Mon, B]Sequences two monadic actions, discarding the value of the first.
Exposed as the
>>operator:m1 >> m2is equivalent tom1.then(m2).
Concrete Types¶
Type |
Implements |
Notes |
|---|---|---|
|
|
States: |
|
|
States: |
|
|
Lazy side-effect wrapper. Call |
|
|
Immutable sequence wrapping a Python list. |
|
|
Guaranteed non-empty. Exposes |
|
|
|
|
|
Numeric monoid under addition. Identity: |
|
|
Numeric monoid under multiplication. Identity: |