mirror of
https://github.com/anoma/juvix.git
synced 2024-12-01 00:04:58 +03:00
f7382caeac
- Closes #1642. This pr introduces syntax for convenient record updates. Example: ``` type Triple (A B C : Type) := | mkTriple { fst : A; snd : B; thd : C; }; main : Triple Nat Nat Nat; main := let p : Triple Nat Nat Nat := mkTriple 2 2 2; p' : Triple Nat Nat Nat := p @Triple{ fst := fst + 1; snd := snd * 3 }; f : Triple Nat Nat Nat -> Triple Nat Nat Nat := (@Triple{fst := fst * 10}); in f p'; ``` We write `@InductiveType{..}` to update the contents of a record. The `@` is used for parsing. The `InductiveType` symbol indicates the type of the record update. Inside the braces we have a list of `fieldName := newValue` items separated by semicolon. The `fieldName` is bound in `newValue` with the old value of the field. Thus, we can write something like `p @Triple{fst := fst + 1;}`. Record updates `X@{..}` are parsed as postfix operators with higher priority than application, so `f x y @X{q := 1}` is equivalent to `f x (y @X{q := 1})`. It is possible the use a record update with no argument by wrapping the update in parentheses. See `f` in the above example. |
||
---|---|---|
.. | ||
Asm | ||
benchmark | ||
Compilation | ||
Core | ||
examplesExpected | ||
Geb/positive | ||
Internal | ||
negative | ||
positive | ||
runtime/positive | ||
smoke/Commands | ||
VampIR | ||
.gitattributes |