Hello,

I was wondering if it is possible to improve template programming and operator overloading with XQUERY 3.?

1) template programming : XQUERY provides a quite natural template mechanism using type switch and instance:

declare function yell($animal) {
if ($animal instance of element()) then
return typeswitch($animal)
  case element(cow) return "Moo"
  default return "..."
else "this is not an animal"
};

However, I wonder whether it could be possible to provide such a mechanism directly at the interpreter level ? For instance, the following code seems coherent and concise :

declare function yell($animal as element(cow) ) {"Moo"}
declare function yell($animal as element() ) {".."}
declare function yell($animal ) {"This is not an animal"}

As far as I understand, XQUERY functions identification seems to be achieve through a couple (name, arity). Would it be difficult to extend it with (name,signature or predicate) ?

2) Operator overloading (quite linked to the previous question)

I don't know how to overload operators with XQUERY. For instance I would like to define something like

declare function array:operator+($left,$right){array:for-each-pair($left,$right,function($a + $b) { $a + $b } )}

Is it possible ?

I know that I can survive writing 

declare function array:plus($left,$right){array:for-each-pair($left,$right,function($a + $b) { $a + $b } )}

but when one start to write algorithmic code, it is far easier and understandable to write $a+$b than array:plus($a,$b)