Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Hint Mode to Functor, Applicative, Monad #126

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion theories/Data/Monads/EitherMonad.v
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion theories/Data/Monads/OptionMonad.v
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions theories/Structures/Applicative.v
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions theories/Structures/Functor.v
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 2 additions & 0 deletions theories/Structures/Monad.v
Original file line number Diff line number Diff line change
@@ -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}
4 changes: 2 additions & 2 deletions theories/Structures/MonadLaws.v
Original file line number Diff line number Diff line change
@@ -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),
10 changes: 5 additions & 5 deletions theories/Structures/Traversable.v
Original file line number Diff line number Diff line change
@@ -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.