feat: cdot notation for tuples
They are morally a parenthesized term.
This commit is contained in:
parent
d0b8dc128b
commit
8b17d4e2d6
3 changed files with 21 additions and 7 deletions
|
|
@ -250,21 +250,21 @@ def expandCDot? (stx : Syntax) : MacroM (Option Syntax) := do
|
|||
- `(· + ·)`
|
||||
- `(f · a b)` -/
|
||||
private def elabCDot (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
|
||||
match (← liftMacroM $ expandCDot? stx) with
|
||||
match (← liftMacroM <| expandCDot? stx) with
|
||||
| some stx' => withMacroExpansion stx stx' (elabTerm stx' expectedType?)
|
||||
| none => elabTerm stx expectedType?
|
||||
|
||||
@[builtinTermElab paren] def elabParen : TermElab := fun stx expectedType? =>
|
||||
@[builtinTermElab paren] def elabParen : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(()) => pure $ Lean.mkConst `Unit.unit
|
||||
| `(($e : $type)) => do
|
||||
| `(()) => return Lean.mkConst `Unit.unit
|
||||
| `(($e : $type)) =>
|
||||
let type ← withSynthesize (mayPostpone := true) $ elabType type
|
||||
let e ← elabCDot e type
|
||||
ensureHasType type e
|
||||
| `(($e)) => elabCDot e expectedType?
|
||||
| `(($e, $es,*)) => do
|
||||
let pairs ← liftMacroM $ mkPairs (#[e] ++ es)
|
||||
withMacroExpansion stx pairs (elabTerm pairs expectedType?)
|
||||
| `(($e, $es,*)) =>
|
||||
let pairs ← liftMacroM <| mkPairs (#[e] ++ es)
|
||||
withMacroExpansion stx pairs (elabCDot pairs expectedType?)
|
||||
| _ => throwError "unexpected parentheses notation"
|
||||
|
||||
@[builtinTermElab subst] def elabSubst : TermElab := fun stx expectedType? => do
|
||||
|
|
|
|||
11
tests/lean/cdotTuple.lean
Normal file
11
tests/lean/cdotTuple.lean
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#eval [1, 2, 3].map (·, 1)
|
||||
|
||||
#eval (·, ·) 1 2
|
||||
|
||||
#eval (., ., .) 1 2 3
|
||||
|
||||
theorem ex1 : [1, 2, 3].map (·, 1) = [(1, 1), (2, 1), (3, 1)] :=
|
||||
rfl
|
||||
|
||||
theorem ex2 : (., .) 1 2 = (1, 2) :=
|
||||
rfl
|
||||
3
tests/lean/cdotTuple.lean.expected.out
Normal file
3
tests/lean/cdotTuple.lean.expected.out
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[(1, 1), (2, 1), (3, 1)]
|
||||
(1, 2)
|
||||
(1, 2, 3)
|
||||
Loading…
Add table
Reference in a new issue