1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-01 00:04:58 +03:00
juvix/tests
Jan Mas Rovira f7382caeac
Record updates (#2263)
- 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.
2023-08-07 12:35:36 +02:00
..
Asm New compilation pipeline (#1832) 2023-03-14 16:24:07 +01:00
benchmark Fix runtime C maybe benchmark example (#2195) 2023-06-16 09:54:13 +01:00
Compilation Record updates (#2263) 2023-08-07 12:35:36 +02:00
Core Fold lets when the bound variable occurs at most once (#2231) 2023-06-29 13:02:10 +02:00
examplesExpected Add a test suite for milestone examples (#1920) 2023-03-24 13:16:26 +00:00
Geb/positive Update to GEB version 0.3.2 (#2244) 2023-07-11 11:02:48 +02:00
Internal Fix reachability analysis with imports in unreachable nested modules (#2062) 2023-05-12 09:53:30 +01:00
negative Record updates (#2263) 2023-08-07 12:35:36 +02:00
positive Record updates (#2263) 2023-08-07 12:35:36 +02:00
runtime/positive Respect fixity in runtime printer (#2182) 2023-06-07 11:44:41 +02:00
smoke/Commands Add field projections for records (#2260) 2023-08-01 09:46:22 +01:00
VampIR The public pragma (#2223) 2023-06-22 18:31:53 +02:00
.gitattributes Juvix C runtime (#1580) 2022-11-03 09:38:09 +01:00