Skip to content
Open
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
15 changes: 11 additions & 4 deletions Cslib/Foundations/Control/Monad/Free.lean
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ variable {F : Type u → Type v} {ι : Type u} {α : Type w} {β : Type w'} {γ

instance : Pure (FreeM F) where pure := .pure

@[simp]
@[simp, grind =]
theorem pure_eq_pure : (pure : α → FreeM F α) = FreeM.pure := rfl

/-- Bind operation for the `FreeM` monad. -/
Expand All @@ -115,7 +115,7 @@ protected theorem bind_assoc (x : FreeM F α) (f : α → FreeM F β) (g : β

instance : Bind (FreeM F) where bind := .bind

@[simp]
@[simp, grind =]
theorem bind_eq_bind {α β : Type w} : Bind.bind = (FreeM.bind : FreeM F α → _ → FreeM F β) := rfl

/-- Map a function over a `FreeM` monad. -/
Expand Down Expand Up @@ -154,14 +154,21 @@ lemma map_lift (f : ι → α) (op : F ι) :
map f (lift op : FreeM F ι) = liftBind op (fun z => (.pure (f z) : FreeM F α)) := rfl

/-- `.pure a` followed by `bind` collapses immediately. -/
@[simp]
@[simp, grind =]
lemma pure_bind (a : α) (f : α → FreeM F β) : (.pure a : FreeM F α).bind f = f a := rfl

@[simp]
@[simp, grind =]
lemma pure_bind' {α β} (a : α) (f : α → FreeM F β) : (.pure a : FreeM F α) >>= f = f a :=
pure_bind a f
Comment on lines +160 to +162
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @kim-em can comment on why the simpNF linter does not reject this due to bind_eq_bind simplifying the LHS?


@[simp, grind =]
lemma bind_pure : ∀ x : FreeM F α, x.bind (.pure) = x
| .pure a => rfl
| liftBind op k => by simp [FreeM.bind, bind_pure]

@[simp, grind =]
lemma bind_pure' : ∀ x : FreeM F α, x >>= .pure = x := bind_pure

@[simp]
lemma bind_pure_comp (f : α → β) : ∀ x : FreeM F α, x.bind (.pure ∘ f) = map f x
| .pure a => rfl
Expand Down
Loading