Skip to content

Commit

Permalink
chore: cleanup some deprecations in tests (#5834)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Oct 25, 2024
1 parent 748f0d6 commit 4c0d12b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions doc/monads/applicatives.lean
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ definition:
-/
instance : Applicative List where
pure := List.pure
seq f x := List.bind f fun y => Functor.map y (x ())
pure := List.singleton
seq f x := List.flatMap f fun y => Functor.map y (x ())
/-!
Notice you can now sequence a _list_ of functions and a _list_ of items.
Expand Down
8 changes: 4 additions & 4 deletions doc/monads/laws.lean
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Applying the identity function through an applicative structure should not chang
values or structure. For example:
-/
instance : Applicative List where
pure := List.pure
seq f x := List.bind f fun y => Functor.map y (x ())
pure := List.singleton
seq f x := List.flatMap f fun y => Functor.map y (x ())

#eval pure id <*> [1, 2, 3] -- [1, 2, 3]
/-!
Expand Down Expand Up @@ -235,8 +235,8 @@ structure or its values.
Left identity is `x >>= pure = x` and is demonstrated by the following examples on a monadic `List`:
-/
instance : Monad List where
pure := List.pure
bind := List.bind
pure := List.singleton
bind := List.flatMap

def a := ["apple", "orange"]

Expand Down
4 changes: 2 additions & 2 deletions doc/monads/monads.lean
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ implementation of `pure` and `bind`.
-/
instance : Monad List where
pure := List.pure
bind := List.bind
pure := List.singleton
bind := List.flatMap
/-!
Like you saw with the applicative `seq` operator, the `bind` operator applies the given function
Expand Down
2 changes: 1 addition & 1 deletion tests/lean/run/subexpr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ theorem Pos.roundtrip :

theorem Pos.append_roundtrip :
true = (List.all
(ps.bind fun p => ps.map fun q => (p,q))
(ps.flatMap fun p => ps.map fun q => (p,q))
(fun (x,y) => (x ++ y) == (Pos.toArray <| (Pos.append (Pos.ofArray x) (Pos.ofArray y))))
) := by native_decide

Expand Down
14 changes: 7 additions & 7 deletions tests/lean/run/treeNode.lean
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
inductive TreeNode :=
inductive TreeNode where
| mkLeaf (name : String) : TreeNode
| mkNode (name : String) (children : List TreeNode) : TreeNode

Expand All @@ -13,11 +13,11 @@ def treeToList (t : TreeNode) : List String :=
r := r ++ treeToList child
return r

@[simp] theorem treeToList_eq (name : String) (children : List TreeNode) : treeToList (.mkNode name children) = name :: List.join (children.map treeToList) := by
@[simp] theorem treeToList_eq (name : String) (children : List TreeNode) : treeToList (.mkNode name children) = name :: List.flatten (children.map treeToList) := by
simp only [treeToList, Id.run, Id.pure_eq, Id.bind_eq, List.forIn'_eq_forIn, forIn, List.forIn]
have : ∀ acc, (Id.run do List.forIn.loop (fun a b => ForInStep.yield (b ++ treeToList a)) children acc) = acc ++ List.join (List.map treeToList children) := by
have : ∀ acc, (Id.run do List.forIn.loop (fun a b => ForInStep.yield (b ++ treeToList a)) children acc) = acc ++ List.flatten (List.map treeToList children) := by
intro acc
induction children generalizing acc with simp [List.forIn.loop, List.map, List.join, Id.run]
induction children generalizing acc with simp [List.forIn.loop, List.map, List.flatten, Id.run]
| cons c cs ih => simp [Id.run] at ih; simp [ih, List.append_assoc]
apply this

Expand All @@ -35,7 +35,7 @@ theorem length_treeToList_eq_numNames (t : TreeNode) : (treeToList t).length = n
| .mkLeaf .. => simp [treeToList, numNames]
| .mkNode _ cs => simp_arith [numNames, helper cs]
where
helper (cs : List TreeNode) : (cs.map treeToList).join.length = numNamesLst cs := by
helper (cs : List TreeNode) : (cs.map treeToList).flatten.length = numNamesLst cs := by
match cs with
| [] => simp [List.join, numNamesLst]
| c::cs' => simp [List.join, List.map, numNamesLst, length_treeToList_eq_numNames c, helper cs']
| [] => simp [List.flatten, numNamesLst]
| c::cs' => simp [List.flatten, List.map, numNamesLst, length_treeToList_eq_numNames c, helper cs']
4 changes: 2 additions & 2 deletions tests/lean/treeMap.lean
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
inductive TreeNode :=
inductive TreeNode where
| mkLeaf (name : String) : TreeNode
| mkNode (name : String) (children : List TreeNode) : TreeNode

open TreeNode in def treeToList (t : TreeNode) : List String :=
match t with
| mkLeaf name => [name]
| mkNode name children => name :: List.join (children.map treeToList)
| mkNode name children => name :: List.flatten (children.map treeToList)
termination_by t
2 changes: 1 addition & 1 deletion tests/lean/treeMap.lean.expected.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
treeMap.lean:8:59-8:69: error: failed to prove termination, possible solutions:
treeMap.lean:8:62-8:72: error: failed to prove termination, possible solutions:
- Use `have`-expressions to prove the remaining goals
- Use `termination_by` to specify a different well-founded relation
- Use `decreasing_by` to specify your own tactic for discharging this kind of goal
Expand Down

0 comments on commit 4c0d12b

Please sign in to comment.