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

Alain Frisch Alain.Frisch at inria.fr
Tue Nov 23 10:08:15 CET 2004


Freeman Huang wrote:
> let updateSalary (<_>[_*] -> <_>[_*])
>   | <salary> [(x & Int)] -> <salary> [ (increase x) ]
>   | <(y)> x -> <(y)> (xtransform x with <salary> [(x & Int)] ->
> [<salary> [ (increase x) ] ] )
> 
> am I missing something?

let updateSalary(x : <_>[_*]) : <_>[_*] =
   let [ y ] =
    xtransform [ x ] with
    <salary>[(x & Int)] -> [ <salary>[(increase x) ] ] in
   y

> And further, I was wondering if the syntax allows making <salary> also
> a parameter?

Patterns are not first-class values, but atoms are, and you can check 
equality. You can write somethink like:

let updateSalary(a : Atom)(x : <_>[_*]) : <_>[_*] =
  let [ y ] =
   xtransform [ x ] with
   z & <(b)>[ (x & Int) ] ->
      if (a = b) then [ <(b)>[ (increase x) ] ] else [ z ]
  in y;;

-- Alain



More information about the Cduce-users mailing list