-
Notifications
You must be signed in to change notification settings - Fork 16
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
Equivalence of map and function types #730
Comments
Further this sentence still uses language that suggests that it's meaningful to talk of "the function signature" of a map; yet we know that a map matches many types of the form map(K,V) and therefore has many function signatures. We often try to pretend that for a given map, there is one map type map(K,V) that is more specific than any other map type that the map conforms to. This is not the case, as is easily shown by looking at the empty map. |
All such subtleties and misunderstandings are due to the fact that we do not have (but do need) at present a None in XPath. None is not the same as the empty sequence
And I think we need to have None in XPath in order to avoid such misunderstandings, and wrong function definitions as We also need a function By definition, any attempt to reference a None would result in error. Thus we wouldn't have to explain why using the empty sequence is sometimes OK but sometimes this results in error. |
@dnovatchev Could you explain please how having the type |
Correct, I got carried away by the proposed use of
As for the signature of a map, it is quite clear:
The empty map is the extreme case of function of 0 arguments that produces None. |
If only it were clear! The matter has caused immense confusion over the years, resulting in recent reopening of the thread at w3c/qt3tests#28 and challenging of currently accepted test results. The root cause of the problem is that for "intentional functions" (i.e not maps and arrays), a function has a signature as a self-contained property and there is no argument about what the signature is. For maps and arrays it's less clear that the concept of having a signature is useful, because maps and arrays don't have a type label of any kind; as with sequences, types are essentially predicates rather than properties, and the "instance of" operator involves inspecting the actual contents. Perhaps the solution is indeed to say that the signature of a map is
(a) $M is an instance of map(xs:anyAtomicType, R), and We also need to say that (a) V is a subtype of R, and |
💯
We will obviously need other "empty-types" such as It is logical and convenient to have just one type nothing() that is a subtype of all these 3 empty-types, so in all these 3 cases we will simply specify the type as nothing(). |
The XPath 3.1 Specification defines "The sequence type empty-sequence() matches a value that is the empty sequence." This by definition falls short of matching an empty array: [ ] or an empty map: map{ }. Thus the proposed type nothing() that is a subtype of |
If we defined the three types Reading your post again, I wonder if you're actually looking for a type that is the union of |
If it is the union, (per my understanding, which may be wrong) then we will need to provide one of the 3 "simple types" every time and this is exactly what we want to avoid. On a related topic: do we still need |
@michaelhkay Shall we have a separate issue for the nothing() type? |
By all means raise a separate issue if you think there are problems that it would solve. |
Fixed by #736. |
It is stated in XPath §3.6.4.2, and probably elsewhere, that
The function signature of a map matching type map(K, V), treated as a function, is function(xs:anyAtomicType) as V?
But V is a sequence type, not an item type, so you can't just tag a '?' onto the end of it. What is intended here by
V?
is a sequence type that is the union ofV
andempty-sequence()
.The text was updated successfully, but these errors were encountered: