agda
agda copied to clipboard
Reopen PR "Add `record where` syntax sugar (#6603)"
This reopens
- #6603
and continues the discussion started there.
There is a few points to discuss and address in the proposed record where
feature:
- The currently implemented semantics of
record where decls[fields]
is in terms oflet decls in record { fields = fields }
. This restricts the declarations to the ones accepted inlet
, which is usually a source of confusion. An alternative semantics would be to define an anonymous moduleM
containingdecls
and then formrecord{M}
. However, there is the technical problem where to placeM
(sincerecord where
is an expression). Also, currently defining a moduleM
would not work as the scope checker would complain about redefinitions of thefields
(see #3801). - If we stick to the
let
semantics, a more suggestive name would berecord let decls
. Keywordwhere
suggests that you can use the declaration forms that are allowed inwhere
blocks. - The current implementation implements the recognition of
record where
(desugaring) but does not produce arecord where
(resugaring). That goes against our ideal to reproduce what the user has written, if at all possible. In this particular case, we would need a newOrigin
for the record expression and use this in the printer. Example:
Current error:open import Agda.Builtin.Equality open import Agda.Builtin.Nat open import Agda.Builtin.Sigma test : record { fst = 1; snd = 2} ≡ record where fst = 3 snd = 4 test = refl
(does not reproduce1 != 3 of type Nat when checking that the expression refl has type record { fst = 1 ; snd = _8 } ≡ record { fst = 3 ; snd = _14 }
record where
). - The current examples in CHANGELOG and docs do not motivate this new sugar, as plain record expressions aren't longer (needing braces and semicolons, but not needing
where
). Better motivation could be supplied, e.g. usingopen
(something of the formrecord where... open M...f = foo
).