lean4-htt/tests/lean/run/cdotTests.lean
Kyle Miller 95bf6793aa
fix: make cdot anonymous function notation handle ambiguous notation (#4833)
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
2024-08-09 21:16:51 +00:00

45 lines
926 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 ·)