xsl-list
[Top] [All Lists]

Re: [xsl] XPath 3.0 How to implement the function composition operator?

2012-10-15 18:02:19
compose is a function that takes two functions as input and produces a third function as output, so it looks like this:

$compose   :=  function($a as function(item()*) as item()*,
                        $b as function(item()*) as item()*)
                     as (function(item()*) as item()*)
{  function($c as item()*) as item()* { $b($a($c)) } }

(Or the other way around. I don't know which way Haskell does it.)

Michael Kay
Saxonica


On 15/10/2012 23:08, Costello, Roger L. wrote:
Hi Folks,

How is function composition implemented in XPath 3.0?

Example: Suppose I want to compose these two function:

     1. increment: this function increases its argument by 1.

     2. double: this function multiplies its argument by 2.

In Haskell I can compose the two functions like so:

     f = double . increment

And then I can apply the composed functions to an argument:

     f 2

The result is 6.

How is f implemented in XPath 3.0?

Here is my attempt, which is not correct:

             let $increment :=  function($x as xs:integer) {$x + 1},
                  $double        :=  function($y as xs:integer) {$y * 2},
                  $compose   :=  function(
                                                                $a as 
function(item()*) as item()*,
                                                                $b as 
function(item()*) as item()*
                                                             )
                                                            as item()*
                                                {$b($a)},
                 $f  :=  $compose($double, $increment)
             return $f(2)

What is the correct way?

/Roger

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--