-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |