Odd behavior of "key" keyword

I just noticed an odd behavior…

Why is it that in the body of a template key is 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.

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 define signatory \this@T{..} -> … but this and the template fields are implicitly in scope.

Which leaves the question under what name do you bring it in scope? key seems like the obvious choice here so we’ve gone with that. So within the maintainer definition the local key variable simply shadows the top level key : HasKey t k => t -> k function. 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.

2 Likes