[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XPath 3.0 How to implement the function composition o

Subject: XPath 3.0 How to implement the function composition operator?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Mon, 15 Oct 2012 22:08:58 +0000
 XPath 3.0 How to implement the function composition  o
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.