This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29870 - Tuple types
Summary: Tuple types
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Requirements for Future Versions (show other bugs)
Version: Candidate Recommendation
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-26 06:42 UTC by Michael Kay
Modified: 2016-09-26 06:42 UTC (History)
0 users

See Also:


Attachments

Description Michael Kay 2016-09-26 06:42:55 UTC
A common use case for maps is to represent composite structures such as the result of fn:random-number-generator, which is a map containing 

number: an xs:double
next: a function
permute: a function

The problem about using maps for such structures is that we can't describe or constrain their type very accurately: this example simply becomes map(xs:string, item()).

We could introduce tuple types simply as new syntax for constraining the type of a map.

declare function fn:random(...) as 
   tuple{number : xs:double, 
         next : function(*),
         permute : function(item()*) as item()*}

The instances of this type would still be maps, and they would still be instances of map(xs:string, item()), and one could use all the same operations (e.g. random($seed)?permute($x)), but the new item type syntax would allow the required type to be specified more descriptively and precisely, and would allow better static type checking.

The feature has been prototyped in Saxon: see http://dev.saxonica.com/blog/mike/2016/09/tuple-types-and-type-aliases.html

(In this particular example it would be nice to be able to make the type recursive, since the "next" function also returns tuples of this type; but that's a separate requirement).