| 1 |
From elpi.apps Require Import derive.std rbuild. |
| 2 |
|
| 3 |
Record foo {A} := { a : nat; b : bool; c : A }. |
| 4 |
#[only(lens)] derive foo. |
| 5 |
|
| 6 |
(* Build a record without mentioning its constructor name *) |
| 7 |
Check « 3 ; false; tt » : foo. |
| 8 |
|
| 9 |
(* This time using labels to change the order of fields *) |
| 10 |
Check « false ; a .= 1 + 2; tt » : foo. |
| 11 |
Check « c .= tt ; a .= 1 + 2; false » : foo. |
| 12 |
|
| 13 |
(* This time ; _ enables padding *) |
| 14 |
Check « c .= tt ; _ » : foo. |
| 15 |
|
| 16 |
(* No type annotation but label *) |
| 17 |
Check « c .= tt; _ ». |
| 18 |
|
| 19 |
(* Update with a lens *) |
| 20 |
Check fun x : foo => |
| 21 |
« x with a .= 3 ». |
| 22 |
|
| 23 |
(* Errors: *) |
| 24 |
Fail Check « c .= tt ». (* Error: not enough fields, maybe use « ... ; _ » *) |
| 25 |
Fail Check « c .= tt; 1; 2; 3; 4 ». (* Error: too many fields *) |
| 26 |
Check « false ». (* « unresolved record » *) |
| 27 |
Fail Check « c .= tt; 1; 2 ». (* Error: |
| 28 |
Illtyped record: Illegal application: |
| 29 |
The term "Build_foo" of type "forall A : Type, nat -> bool -> A -> foo" |
| 30 |
cannot be applied to the terms |
| 31 |
"?e0" : "Type" |
| 32 |
"1" : "nat" |
| 33 |
"2" : "nat" |
| 34 |
"tt" : "unit" |
| 35 |
The 3rd term has type "nat" which should be a subtype of "bool". *) |
| 36 |
|
| 37 |
Record bar := { f : @foo nat; d : nat }. |
| 38 |
#[only(lens)] derive bar. |
| 39 |
Record baz := { w : bar }. |
| 40 |
#[only(lens)] derive baz. |
| 41 |
|
| 42 |
(* Update with a composed lens *) |
| 43 |
Check fun x : baz => |
| 44 |
« x with w#f#c .= 3 ». |
| 45 |
|
| 46 |
(* # is just catcomp from ssrfun *) |
| 47 |
Import ssrfun. |
| 48 |
Check fun x : baz => |
| 49 |
« x with (w \; f \; c) .= 3 ». |
| 50 |
|
| 51 |
|
| 52 |
|