karpal-free
Free constructions for the Industrial Algebra ecosystem.
What's included
| Type | Description |
|---|---|
Coyoneda<F, A> |
Free functor — makes any type constructor into a Functor by deferring fmap |
Yoneda<F, A> |
Yoneda lemma as a data type — O(1) map fusion via CPS |
Free<F, A> |
Free monad — Pure(A) | Roll(F<Free<F, A>>) |
Cofree<F, A> |
Free comonad — annotated recursive structure with head + tail |
Freer<F, A> |
Freer monad — no F: Functor requirement (uses Coyoneda internally) |
Lan<G, H, A, B> |
Left Kan extension |
Ran |
Right Kan extension (trait-based) |
Codensity<F, A> |
CPS monad — no F bounds for pure/fmap/chain |
Density<W, A> |
CPS comonad — no W bounds for extract/fmap |
Day<F, G, A, B, C> |
Day convolution — combines two functors via a binary function |
FreeAp<F, A> |
Free applicative — supports static analysis via count_effects |
FreeAlt<F, A> |
Free alternative — Vec<FreeAp<F, A>> |
Usage
use ;
use OptionF;
// Coyoneda: fmap without Functor
let co = lift
.fmap
.fmap;
assert_eq!;
// Yoneda: O(1) map fusion
let yo = lift
.fmap
.fmap;
assert_eq!;
Free monad
use Free;
use OptionF;
// Pure values
let pure: = pure;
// Roll wraps one layer of the functor
let rolled: = roll;
Features
std(default) — enablesallocand standard library supportalloc— enables heap-allocated types (Box<dyn Fn>)- With
default-features = false, the crate isno_stdcompatible (but most types requirealloc)
License
MIT OR Apache-2.0