Fixes an issue where each alternative in choice nodes would get their own arguments. Now cdot function expansion is aware of choice nodes. Also modifies the variable naming so that multi-argument functions like `(· + ·)` expand as `fun x1 x2 => x1 + x2` rather than `fun x x_1 => x + x_1`. Closes #4832
45 lines
926 B
Text
45 lines
926 B
Text
|
||
|
||
class Inc (α : Type) :=
|
||
(inc : α → α)
|
||
|
||
export Inc (inc)
|
||
|
||
instance {α} [Inc α] : Inc (List α) :=
|
||
{ inc := (·.map inc) }
|
||
|
||
instance : Inc Nat :=
|
||
{ inc := Nat.succ }
|
||
|
||
#guard inc 10 == 11
|
||
#guard inc [1, 2, 3] == [2, 3, 4]
|
||
|
||
theorem ex1 : [(1, "hello"), (2, "world")].map (·.1) = [1, 2] :=
|
||
rfl
|
||
|
||
theorem ex2 : [(1, "hello"), (2, "world")].map (·.snd) = ["hello", "world"] :=
|
||
rfl
|
||
|
||
def sum (xs : List Nat) : Nat :=
|
||
(·.2) $ Id.run $ StateT.run (s:=0) do
|
||
xs.forM fun x => modify (· + x)
|
||
|
||
#guard sum [1, 2, 3, 4] == 10
|
||
|
||
theorem ex3 : sum [1, 2, 3] = 6 :=
|
||
rfl
|
||
|
||
theorem ex4 : sum [1, 2, 3, 4] = 10 :=
|
||
rfl
|
||
|
||
/-!
|
||
Check that ambiguous notation inside cdot notation still has only a single argument.
|
||
(Need to process choice nodes specially.)
|
||
-/
|
||
|
||
def tag (_ : α) (y : α) := y
|
||
notation "f" x => tag 1 x
|
||
notation "f" x => tag "2" x
|
||
/-- info: fun x => (f x).length : String → Nat -/
|
||
#guard_msgs in
|
||
#check (String.length <| f ·)
|