You might like to look at how Evan Lenz tackled this idea in Carrot

http://www.balisage.net/Proceedings/vol7/html/Lenz01/BalisageVol7-Lenz01.html

Michael Kay
Saxonica
[email protected]
+44 (0) 118 946 5893




On 9 Jan 2015, at 07:51, jean-marc Mercier <[email protected]> wrote:

> Hello,
> 
> I would like to discuss the opportunity to improve template programming and 
> operator overloading for XQUERY ?
> 
> 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"
> };
> 
> I think that it could be worthwhile 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, the previous code violates  XQUERY functions 
> identification, achieved through a couple (name, arity). Would it be 
> difficult to extend this identification mechanism ?
> 
> 2) A quite interesting application to 1) would be to define operator 
> overloading 
> 
> Indeed, I don't know how to overload operators with XQUERY. For instance I 
> would like to define something like
> 
> declare function 
> operator+($left,$right){fn:for-each-pair($left,$right,function($a + $b) { $a 
> + $b } )}
> 
> I know that I can survive writing 
> 
> declare function 
> local:plus($left,$right){fn: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). Moreover, it can be 
> used to expressions template, quite useful for linear algebra.
> _______________________________________________
> [email protected]
> http://x-query.com/mailman/listinfo/talk

_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to