[xsl] RE: mapping (Was: Re: Re: . in for)

Subject: [xsl] RE: mapping (Was: Re: Re: . in for)
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 9 Jan 2002 04:58:13 -0800 (PST)
> > but this organisation doesn't make it particularly easy to pipe
> > functions together (or at least not in a similar way to location
> > paths).
> I'm sure David C or Dimitre could extend this to a piped form?
> Guessing,
>   select='map (fnA(), (map (fnb(), $departments)))'
> which maps function A over the result set of mapping function b
> over $departments?

In my earlier message "Higher-order function support as means to reduce the
"standard" operators/functions":


it was shown how one could write the map function from scratch if XPath supported
higher-order functions.

 map     ::  [a] -> [a]
 map f    =  foldl ((:).f ) [ ]

The piping mentioned above is implemented by another function -- multiMap:

 multiMap :: [a] -> [a -> a] -> [a]
 multiMap xs fs  = foldr map xs fs

It is ***so easy*** to express new functions in a language which has higher-order

And the piping above will be expressed as:

   select='multiMap ($departments,
                      (fnA(), fnb(), ... , fnX())

In another message it was also shown how to optimise a long 'piping' of maps into a
single map:

        (map f1)
  <<.>> (map f2)
  <<.>> (map fN)   $sequence

is equal to:

map (f1 <<.>> f2 ...  <<.>> fN) $sequence

where <<.>> is the functional composition operator.

Certainly, multiMap can be modified to take advantage of this optimisation.

> Like this more and more!

It is easy to fall in love with FP.

Dimitre Novatchev.

Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread