chore: cleanup some deprecations in tests (#5834)
This commit is contained in:
parent
748f0d6c15
commit
4c0d12b3f1
7 changed files with 19 additions and 19 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
/-!
|
||||
|
|
@ -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"]
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
inductive TreeNode :=
|
||||
inductive TreeNode where
|
||||
| mkLeaf (name : String) : TreeNode
|
||||
| mkNode (name : String) (children : List TreeNode) : TreeNode
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue