-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add syntax support for record updates #1642
Comments
The above record update syntax doesn't play well with the proposed syntax for named arguments: Named arguments automatically provide record creation syntax:
is just
But then
would desugar to
and this conflicts with the record update syntax. I propose to introduce a keyword
|
I think it would be convenient, especially in combination with traits, to also allow trait
type Encoding (A : Type) := MkEncoding {
encode : A -> Field;
decode : Field -> A;
}; one could write: type E (A : Type) :=
| C1 : A -> E
| C2 : E;
instance
encoding : {A : Type} -> {{Encoding A}} -> Encoding (E A);
encoding := MkEncoding with {
encode : E A -> Field;
encode (C1 x) := encode x + 1;
encode C2 := 0;
decode : Field -> E A;
decode zero := C2;
decode (suc x) := C1 (decode x);
}; |
I think adding the |
- 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.
An update for
A
is written as follows:The text was updated successfully, but these errors were encountered: