-
Notifications
You must be signed in to change notification settings - Fork 15
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
map:empty, map:exists ← array:empty, array:exists #827
Comments
I think my preference would be to have |
What about: array:any ? |
Which reminds me that we don't currently have array:some() and array:every(). Note that I think we're in danger of providing too many simple functions that do trivial things, and neglecting the more challenging problems. |
I think here we are going into another, very important topic. Here are a few thoughts on this: This danger is due to the fact that we have sequences, arrays, maps, ..., and maybe we will have other types of collections in the future. And for each of these types of collections we have to define essentially the same functions, such as head, tail, sub-sequence / sub-whatever-collection, slice, items/members-at, etc .... So, if we have As I have pointed in other issues, we need to have a common base-type for any collection and define these I am not satisfied with the explanation that this is not possible due to the fact that the sequence is the most-general type. As in other languages, we could introduce ordered type resolution (like MRO in Python). For example, in: let $collection as union(generator(*), item()*) := Expr-giving-collection If every type of collection is a generator, then the Ordered type resolution matches the types in the union in order and assigns the first-found matching type to $collection. Thus, $collection will be treated as a generator and not just as a sequence. In case all types of collections can be represented as generators, then we don't need different It is hidden (as it must be!) from the user that generators that are sequences and generators that are arrays would have different internal implementations. |
Yes, indeed, it would be nice if the data model were different. However, a year or more of the development time for the 3.1 specs was taken up with trying to find a better way of modelling arrays that retained backwards compatibility. The fact that we failed to come up with a better solution then doesn't mean that no better solution is possible, but it does mean that it's a swamp I'm very reluctant to enter again. |
This is the beauty of the Ordered Type Resolution that it does not affect the XDM in any way, it is used to dynamically specify the best type during the evaluation of a specific expression. An array let $ar as union(array(*), item()*) := [1, 2, 3]
return
head($ar) will produce:
If we want the array to be treated as a sequence of one item, then this expression: let $ar as item()* := [1, 2, 3]
return
head($ar) will produce:
And if all collection types implement a given set of functions defined on generators, and thus can be considered generators, then it becomes unnecessary to have different definitions for functions such as To repeat again: No changes to the XDM are required in order to use OTR (Ordered Type Resolution) during expression evaluation. |
You're proposing a change to the type system. It's not clear whether you are proposing that selection of array:head() in preference to fn:head() should be based on the static type of the expression $ar, or the dynamic type of the value of $ar, but either way, it's a very substantial change to our specs:
|
Yes, the change is significant and would be very useful. It solves the huge burden of having to define essentially the same functions once for sequences, once for arrays, once for maps, ..., etc, over and over again. Maybe even something like using the arrow operator and the treat as operator here would be more instructive: ($ar treat as array(*)) => head() Both the proposed Ordered Type Resolution and/or the treat as operator can be used to achieved this. Everyone would be grateful if we have this in the language and thus reduce the number of functions 2-3 times. |
I think that technically, it's reducing the number of function names, not the number of functions. You're essentially arguing for a mechanism for overloading names so they can refer to different functions depending on the context (or the arguments). And most of the suggestions for disambiguating the function name seem to involve more complexity than just adding a namespace prefix to discriminate them. The objective surely is to come up with something that involves less complexity than the current mechanism. |
I don't think it's challenging for users to decide between Talking about |
If we no-longer care about these "different functions" then they would be internal to the implementation and the user will work only with the functions that are explicitly provided. So indeed, this reduces the number of user-visible functions.
Complexity is inherent in everything and one can argue that "uniform complexity" is useful as it doesn't bring confusion, such as trying to remember which function in which namespace does exactly what. |
Closed (see #969). |
We have
array:empty
andarray:exists
, but no equivalent functions for maps.I think we have decided to live with the ambiguity (discussed in #229) that
map:exists(map {})
will returnfalse
although the “map exists”. Same for arrays.The text was updated successfully, but these errors were encountered: