Odd behavior of "key" keyword
- Leonid_RozenbergOP
I just noticed an odd behavior…
Why is it that in the body of a template
keyis a function to get the key, but in the maintainer field it is the key?That does feel like a right natural behavior, but now that I’ve noticed it. It does feel odd.
- cocreature 2
The maintainers need to be a function
Key -> [Party]independent of the rest of the template (otherwise you could not compute maintainers for negative lookups).So somehow we need to let users define that function. We could explicitly ask for a lambda
maintainer \key -> …but we’ve chosen to bring the key in scope as a variable similar to how you don’t definesignatory \this@T{..} -> …butthisand the template fields are implicitly in scope.Which leaves the question under what name do you bring it in scope?
keyseems like the obvious choice here so we’ve gone with that. So within themaintainerdefinition the localkeyvariable simply shadows the top levelkey : HasKey t k => t -> kfunction. It is somewhat similar to how it’s relatively common to bring in record field values in scope via their names using record wildcards which then shadow the top-level record selectors.