module Meta.Idiom where
Meta: Idiomπ
The Idiom
class, probably better
known as Applicative
(from languages like Haskell and the
Agda standard library), captures the βeffects with parallel
compositionβ, where an βeffectβ is simply a mapping from types to types,
with an arbitrary adjustment of universe levels:
record Effect : TypeΟ where constructor eff field {adj} : Level β Level β : β {β} β Type β β Type (adj β)
The adjustment of universe levels lets us consider, for example, a
βpower setβ effect, where the adjustment is given by lsuc
.
In most cases, Agda can infer the adjustment, so we can use the eff
constructor.
record Map (M : Effect) : TypeΟ where private module M = Effect M field map : β {β} {β'} {A : Type β} {B : Type β'} β (A β B) β M.β A β M.β B record Idiom (M : Effect) : TypeΟ where private module M = Effect M field β¦ Map-idiom β¦ : Map M pure : β {β} {A : Type β} β A β M.β A _<*>_ : β {β} {β'} {A : Type β} {B : Type β'} β M.β (A β B) β M.β A β M.β B infixl 4 _<*>_ open Idiom β¦ ... β¦ public open Map β¦ ... β¦ public infixl 4 _<$>_ _<&>_ _<$>_ : β {β β'} {M : Effect} β¦ _ : Map M β¦ {A : Type β} {B : Type β'} β (A β B) β M .Effect.β A β M .Effect.β B f <$> x = map f x _<$_ : β {β β'} {M : Effect} β¦ _ : Map M β¦ {A : Type β} {B : Type β'} β B β M .Effect.β A β M .Effect.β B c <$ x = map (Ξ» _ β c) x _<&>_ : β {β β'} {M : Effect} β¦ _ : Map M β¦ {A : Type β} {B : Type β'} β M .Effect.β A β (A β B) β M .Effect.β B x <&> f = map f x module _ {M N : Effect} (let module M = Effect M; module N = Effect N) β¦ _ : Map M β¦ β¦ _ : Map N β¦ {β} {β'} {A : Type β} {B : Type β'} where _<<$>>_ : (A β B) β M.β (N.β A) β M.β (N.β B) f <<$>> a = (f <$>_) <$> a _<<&>>_ : M.β (N.β A) β (A β B) β M.β (N.β B) x <<&>> f = f <<$>> x when : β {M : Effect} (let module M = Effect M) β¦ app : Idiom M β¦ β Bool β M.β β€ β M.β β€ when true t = t when false _ = pure tt unless : β {M : Effect} (let module M = Effect M) β¦ app : Idiom M β¦ β Bool β M.β β€ β M.β β€ unless false t = t unless true _ = pure tt