Re: Extension candidates

John Snelson <[email protected]> Fri, 12 Dec 2008 12:26:42 +0000
Newsgroups gmane.text.xml.xslt.extensions
Message-ID <[email protected]>
Michael Kay wrote:
>> Let me ask a question that no one on the XQuery WG has yet 
>> been able to answer compellingly: why do you need node 
>> references if you have sequences of sequences (or some other 
>> more complex structure)?
> 
> I'd like to suggest we think of a first-class function as our basic building
> block: a third kind of item.
> 
> Then we can have a function ref($node) that returns an anonymous
> zero-argument function which, when called, yields $node. So we have node
> references as an almost-primitive value; they look primitive, but actually
> ride on the back of higher-order functions. Whether the reference can be
> strongly typed depends on whether higher-order functions can be strongly
> typed; I suggest we go for weak typing for the moment, as we're trying to
> implement this in terms of extensions.
> 
> We can easily generalize ref() so the argument is any sequence, not just a
> node.
> 
> Since a function is an item, a reference is an item, and can therefore be
> part of a sequence. So we have nested sequences (of a kind). We can then
> think about what operators we might want over nested sequences.
> 
> So I'm inclined to build "nested sequences" from references as the
> primitive.

I like the idea, and think it makes a lot of sense. I'm more than happy 
to share the work I've already done on adding higher order functions to 
XQuery.

There are a couple of issues I think we need to work out:

1) The work I've done on higher order functions adds syntax for 
addressing named functions, as well as for lambda expressions with 
closures. I can see how we could support the former just by defining 
extension functions, but not the latter.

2) If we don't support higher order functions with closures, it's 
unclear to me how we could use higher order functions to represent a 
sequence reference.

John

-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:            http://oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net