-
Notifications
You must be signed in to change notification settings - Fork 17
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
Defining names for parameters on typed function tests #1136
Comments
Thanks for the separate proposal. I’m not 100% sure I understand how 4. could look like in practice. Could you add a little example for it? |
declare function fn:index-where(
$input as item()*,
$predicate as function(
$item as item(),
$position as xs:integer
) as xs:boolean
) as xs:integer* {
for $it at $pos in $input
where $predicate(item := $it, position := $pos)
return $pos
}; Here, the processor resolves |
I wonder how that would go hand in hand with the existing semantics:
|
This proposal introduces some static type inferencing into the language, something which we have previously avoided (except for the limited purpose of streamability analysis in XSLT). If we keep it very tightly constrained -- associating the explicitly declared type of a variable or parameter with references to that variable or parameter -- then this might be manageable. But I worry that it could easily feature-creep into something more complex. Consider
This isn't going to work because $actual-predicate doesn't have a type declaration providing the parameter names. He could try:
but is this actually usable? To make it more usable, we have to start introducing more complex type inferencing rules. Even without this, we're making life tougher for implementations -- for example you can't now inline a variable reference without retaining information from its type declaration. To what benefit? |
It would make sense for I think it makes sense for function coercion rules, subsumption rules, etc. to allow different names -- otherwise there would be incompatibilities with 3.1 -- and use the names in the nearest scope. That is, given:
the And given:
the variable |
@michaelhkay I'm happy to keep this constrained, such that your There are two parts to this proposal:
I don't expect this specific proposal to go any/much farther than that. Doing so would require the dynamic proposal that @ChristianGruen is putting forward. |
An even smaller step (hopefully not too small) would be to introduce optional parameter names, but to utilize them only for documentation and error messages. This would address reason 1-3 of this proposal. Closely related: #981. |
I'm happy to treat 1-3 and 4 as two separate proposals. |
I do think we should avoid the "thin end of the wedge" effect of static type inferencing. I don't think it would be acceptable to allow parameter names on |
I agree that allowing names purely for documentation purposes seems a sensible idea. It's hard to separate this, however, from the fact that according to the data model, a function item has parameters with names. Currently there is no way of determining what the names are, and I don't think there is anything in the language that would be any different if they didn't have names, but we should make a decision whether to retain the names and make use of them, or to drop them. |
Now that we introduce keyword parameters with version 4, I think it would be just consistent to keep the names as well. |
When defining the type of a higher-order function parameter, you cannot currently specify the names of the parameters of that higher-order function.
Allowing this can be useful for variou reasons:
Thus, you could declare e.g. index-where like this:
The text was updated successfully, but these errors were encountered: