[cduce-users] a generic update(map) function

Giuseppe Castagna Giuseppe.Castagna at ens.fr
Tue Nov 23 01:10:09 CET 2004

Freeman Huang wrote:
> Hi, all,
> I am new to CDuce and was wondering if I can write a generic
> program to update all values of a specific type of element, just
> like a general map function. for example if I want to increase
> everybody's salary:
> type Salary = <salary> [Int]
> let increase (Int -> Int) x-> x+100
> let updateSalary (Any -> Any)
>   |<salary> [(x & Int)] -> <salary> [ (increase x) ]
>   |<(y)> x & [_*] -> <(y)> (map x with z -> updateSalary z)
>   |x -> x

Just a parsing problem
write the second branch as

   |<(y)>( x & [_*] ) -> <(y)> (map x with z -> updateSalary z)

Otherwise the pattern is parsed as
(<(y)> x) & [_*]

and the intersection of an XML element and a sequence is Empty (so the 
pattern cannot ever match)

BTW, to iterate over XML trees there is the xtransform iterator.


More information about the Cduce-users mailing list