[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: XPath 3.0 How to implement the function compositio
Subject: Re: XPath 3.0 How to implement the function composition operator?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 16 Oct 2012 08:43:52 +0100
|
See the list of changes for Saxon 9.4 at
http://www.saxonica.com/documentation9.4-demo/index.html#!changes/xp30-94
<quote>
The XQuery/XPath 3.0 parser has been extended to support partial
function application ("?" as a function argument) in dynamic function
calls. Previously this feature was supported only in direct function
calls to a named function.
</quote>
Michael Kay
Saxonica
On 16/10/2012 01:56, Dimitre Novatchev wrote:
I thought that using the argument placeholder "?" could be used to
specify a more readable implementation.
However it seems tht Saxon EE 9.3.05 (coming with oXygen) doesn't
support argument place holders.
For this query:
let $f := function($m as xs:integer, $n as xs:integer) as xs:integer
{$m + $n}
return
$f(5, ?)(3)
an error message is raised:
Unexpected token "?" in path expression
Start location: 24:0
URL: http://www.w3.org/TR/xpath20/#ERRXPST0003
Could someone, please, explain what is the issue with this expression?
Cheers,
Dimitre
On Mon, Oct 15, 2012 at 4:02 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|