Skip to content

Commit

Permalink
Add Hint Mode to Functor, Applicative, Monad
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysxia authored and liyishuai committed Jan 8, 2024
1 parent c315bb0 commit aaf6849
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion theories/Data/Monads/EitherMonad.v
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Section except.
}.

Global Instance MonadT_eitherT : MonadT eitherT m :=
{ lift := fun _ c => mkEitherT (liftM ret c) }.
{ lift := fun _ c => mkEitherT (liftM inr c) }.

Global Instance MonadState_eitherT {T} (MS : MonadState T m) : MonadState T eitherT :=
{ get := lift get
Expand Down
2 changes: 1 addition & 1 deletion theories/Data/Monads/OptionMonad.v
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Section Trans.
{ mzero _A := mkOptionT (ret None) }.

Global Instance MonadT_optionT : MonadT optionT m :=
{ lift _A aM := mkOptionT (liftM ret aM) }.
{ lift _A aM := mkOptionT (liftM Some aM) }.

Global Instance State_optionT {T} (SM : MonadState T m) : MonadState T optionT :=
{ get := lift get
Expand Down
2 changes: 2 additions & 0 deletions theories/Structures/Applicative.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Class Applicative@{d c} (T : Type@{d} -> Type@{c}) :=
; ap : forall {A B : Type@{d}}, T (A -> B) -> T A -> T B
}.

Global Hint Mode Applicative ! : typeclass_instances.

Module ApplicativeNotation.
Notation "f <*> x" := (ap f x) (at level 52, left associativity).
End ApplicativeNotation.
Expand Down
2 changes: 2 additions & 0 deletions theories/Structures/Functor.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Set Strict Implicit.
Polymorphic Class Functor@{d c} (F : Type@{d} -> Type@{c}) : Type :=
{ fmap : forall {A B : Type@{d}}, (A -> B) -> F A -> F B }.

Global Hint Mode Functor ! : typeclass_instances.

Polymorphic Definition ID@{d} {T : Type@{d}} (f : T -> T) : Prop :=
forall x : T, f x = x.

Expand Down
2 changes: 2 additions & 0 deletions theories/Structures/Monad.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Class Monad@{d c} (m : Type@{d} -> Type@{c}) : Type :=
; bind : forall {t u : Type@{d}}, m t -> (t -> m u) -> m u
}.

Global Hint Mode Monad ! : typeclass_instances.

Section monadic.

Definition liftM@{d c}
Expand Down
4 changes: 2 additions & 2 deletions theories/Structures/MonadLaws.v
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Section MonadLaws.
Context {S : Type}.

Class MonadStateLaws (MS : MonadState S m) : Type :=
{ get_put : bind get put = ret tt
{ get_put : bind get put = ret tt :> m unit
; put_get : forall x : S,
bind (put x) (fun _ => get) = bind (put x) (fun _ => ret x)
bind (put x) (fun _ => get) = bind (put x) (fun _ => ret x) :> m S
; put_put : forall {A} (x y : S) (f : unit -> m A),
bind (put x) (fun _ => bind (put y) f) = bind (put y) f
; get_get : forall {A} (f : S -> S -> m A),
Expand Down
10 changes: 5 additions & 5 deletions theories/Structures/Traversable.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Polymorphic Class Traversable@{d r} (T : Type@{d} -> Type@{r}) : Type :=
}.

Polymorphic Definition sequence@{d r}
{T : Type@{d} -> Type@{d}}
{T : Type@{d} -> Type@{r}}
{Tr:Traversable T}
{F : Type@{d} -> Type@{d}} {Ap:Applicative F} {A : Type@{d}}
: T (F A) -> F (T A) := mapT (@id _).
{F : Type@{d} -> Type@{r}} {Ap:Applicative F} {A : Type@{d}}
: T (F A) -> F (T A) := mapT (@id (F A)).

Polymorphic Definition forT@{d r}
{T : Type@{d} -> Type@{d}}
{Tr:Traversable T} {F : Type@{d} -> Type@{d}} {Ap:Applicative F}
{T : Type@{d} -> Type@{r}}
{Tr:Traversable T} {F : Type@{d} -> Type@{r}} {Ap:Applicative F}
{A B : Type@{d}} (aT:T A) (f:A -> F B) : F (T B)
:= mapT f aT.

0 comments on commit aaf6849

Please sign in to comment.