anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
457 stars 53 forks source link

Add builtin Functor / Applicative / Monad #2354

Open janmasrovira opened 1 year ago

janmasrovira commented 1 year ago

Suggested Juvix implementation:

trait
type Functor (F : Type -> Type) :=
  mkFunctor {fmap : {A B : Type} -> (A -> B) -> F A -> F B};

trait
type Applicative (F : Type -> Type) :=
  mkApplicative {
    functor : Functor F;
    pure : {A : Type} -> A -> F A;
    ap : {A B : Type} -> F (A -> B) -> F A -> F B;
  };

trait
type Monad (M : Type -> Type) :=
  mkMonad {
    applicative : Applicative M;
    bind : {A B : Type} -> M A -> (A -> M B) -> M B;
  };

I've not included return in the Monad trait because it's redundant.

jonaprieto commented 1 year ago

Possible syntaxes discussed during the call: