Re: [xsl] Looking for a shorter mapping expression

Subject: Re: [xsl] Looking for a shorter mapping expression
From: Dimtre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sun, 5 Dec 2004 23:38:40 +1100
On 05 Dec 2004 11:47:20 +0000, Colin Paul Adams
<colin@xxxxxxxxxxxxxxxxxx> wrote:
> >>>>> "Dimtre" == Dimtre Novatchev <dnovatchev@xxxxxxxxx> writes:
> 
>    >> How about:
>    >>
>    >> f:a ($pFun, $pList)
>    >>
>    >> :-) :-) :-)
>    >>
>    >> I don't understand the compactness requirement.
> 
> 
>    Dimtre> It can be very essential -- if the "/" operator allowed an
>    Dimtre> arbitrary sequence on the left, then it would be
>    Dimtre> preferrable to f:map()
> 
>    Dimtre> But I'm not satisfied at all with the currently (un)
>    Dimtre> available ways to define the type of such higher order
>    Dimtre> operators in XPath2.
> 
> Don't you mean XSLT 2.0

No, "/" is an XPath operator, which is used in path expressions. It is
also a higher-order operator, whose domain and codomain types are not
defined (XPath has access to the datatypes of nodes -- as found in
PSVI, to the types of variables (from the context if they are
externally passed) , to the types of literals -- constructed during
lexical analysis and to the types of externally defined functions
(like xsl:function) -- as available in the context.

However, "/" is not externally defined and there do not seem to be any
suitable facilities to describe its type -- either in XSD or those
available in XSLT 2.0.

Its first (left-hand) operand may be any expression evaluating to a
sequence of nodes  (generally of differing types ) (sorted by document
order and with no duplicates) and its second operand is even more
unrestricted as it can be a function of any (suitable) type returning
any type (of either a node or an atomic value).

What is needed in order to define the type of such functions is a
*type expression*. More specifically, I am not aware of any facility
available in XSLT 2.0 to describe the type of an argument, which
argument is a function -- this is not present, because higher order
functions are not present in the language.

> 
>    Dimtre> Compare to the strict type definition in Haskell:
> 
>    Dimtre>         map :: (a -> b) -> [a] -> [b]
> 
> I see what you mean - for f:map you currently have:
> 
>    <xsl:function name="f:map" as="item()*">
>      <xsl:param name="pFun" as="element()"/>
>      <xsl:param name="pList1" as="item()*"/>
> 
> whereas what you want is:
> 
>    <xsl:function name="f:map" like="pList1">
>      <xsl:param name="pFun" as="element()"/>
>      <xsl:param name="pList1" as="item()*"/>

Actually, what would be correct is something like this:

    <xsl:function name="f:map" as="codomTypeVariable*">
      <xsl:param name="pFun" as="function()" domain="domTypeVariable"
codomain="codomTypeVariable"/>
      <xsl:param name="pList1" as="domTypeVariable*"/>

of course, not everything can be expressed. Thus, even using Haskell's
type expression it is not possible to describe in them that the result
of f:map() and $pList1 should be of the same cardinality.



> 
> which is not valid XSLT 2.0.
> And I guess it's probably too late to have such a proposal considered.

I guess this would be the main contribution of XPath 3.0.

Cheers,
Dimitre.

Current Thread