From 54adc9a1595195af3df4dc0defe3dbd774361f26 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Wed, 4 Sep 2019 10:26:19 +0100 Subject: [PATCH] Fantasyland traits --- ... => fantasy_land_first_class_modules.gleam | 0 fantasy_land_traits.gleam | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+) rename fantasy_land.gleam => fantasy_land_first_class_modules.gleam (100%) create mode 100644 fantasy_land_traits.gleam diff --git a/fantasy_land.gleam b/fantasy_land_first_class_modules.gleam similarity index 100% rename from fantasy_land.gleam rename to fantasy_land_first_class_modules.gleam diff --git a/fantasy_land_traits.gleam b/fantasy_land_traits.gleam new file mode 100644 index 0000000..c4632fd --- /dev/null +++ b/fantasy_land_traits.gleam @@ -0,0 +1,83 @@ +pub trait Setoid { + fn equals(Self, Self) -> Bool +} + +pub trait Ord { + fn less_than_equal(Self, Self) -> Bool +} + +pub trait Semigroup { + fn concat(Self, Self) -> Self +} + +pub trait Monoid: Semigroup { + fn empty() -> Self +} + +pub trait Group: Monoid { + fn invert(Self) -> Self +} + +pub trait Semigroupoid { + fn compose(Self(i, j), Self(j, k)) -> Self(i, k) +} + +pub trait Category: Semigroupoid { + fn id() -> Self(i, k) +} + +pub trait Filterable { + fn filter(Self(a), fn(a) -> Bool) -> Self(a) +} + +pub trait Functor { + fn map(Self(a), fn(a) -> b) -> Self(b) +} + +pub trait Contravariant { + fn contramap(Self(b), fn(a) -> b) -> Self(a) +} + +pub trait Apply: Functor { + fn ap(Self(fn(a) -> b), Self(a)) -> Self(b) +} + +pub trait Apply { + fn ap(Self(fn(a) -> b), Self(a)) -> Self(b) +} + +pub trait Applicative: Apply { + fn of(a) -> Self(a) +} + +pub trait Alt: Functor { + fn alt(Self(a), Self(a)) -> Self(a) +} + +pub trait Plus: Alt { + fn zero() -> Self(a) +} + +pub trait Alternative: Applicative + Plus + +pub trait Chain: Apply { + fn chain(Self(a), fn(a) -> Self(b)) -> Self(b) +} + +pub trait Monad: Applicative + Self + Chain + +pub trait Foldable { + fn reduce(Self(b), a, fn(a) -> b) -> b +} + +pub trait Extend: Functor { + fn extend(Self(a), fn(Self(a)) -> a) -> Self(b) +} + +pub trait Comonad: Extend { + fn extract(Self(a)) -> a +} + +pub trait Traversable { + fn traverse(Self(a), Applicative(u), u(b)) -> u(Self(b)) +}