Skip to content

Commit

Permalink
notation let' (x,y) := v; b
Browse files Browse the repository at this point in the history
which expands to
```
let p := v
let x:= p.1
let x:= p.2
b
```
rather then to match like normal let binding
  • Loading branch information
lecopivo committed Dec 5, 2024
1 parent 37a1883 commit 7d1c9b0
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions SciLean/Meta/Notation/Let'.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

namespace SciLean

/-- Variant of let binding for product pattern that does not desugar into match but into
bunch of other let bindings and projections.
For examples
```
let' (x,y) := v;
b
```
expands into
```
let p := v
let x := p.1
let y := p.2
b
```
-/
syntax (name:=let'_syntax) "let'" "(" ident,* ")" ":=" term ";" term : term

-- TODO: make sure it works for arbitrary number of identitfiers and ideally for arbitrary pattern.
@[inherit_doc let'_syntax]
macro_rules
| `(let' ($x,$y) := $v; $b) =>
`(let x := $v
let $x := Prod.fst x
let $y := Prod.snd x
$b)
| `(let' ($x,$y,$z) := $v; $b) =>
`(let x := $v
let $x := Prod.fst x
let $y := Prod.fst (Prod.snd x)
let $z := Prod.snd (Prod.snd x)
$b)

| `(let' ($x,$y,$z,$w) := $v; $b) =>
`(let x := $v
let $x := Prod.fst x
let $y := Prod.fst (Prod.snd x)
let $z := Prod.fst (Prod.snd (Prod.snd x))
let $w := Prod.snd (Prod.snd (Prod.snd x))
$b)


@[inherit_doc let'_syntax]
macro "let'" "(" "(" x:ident "," y:ident ")" "," z:ident ")" ":=" v:term ";" b:term : term =>
`(let x := $v
let $x := x.1.1
let $y := x.1.2
let $z := x.2
$b)

0 comments on commit 7d1c9b0

Please sign in to comment.