diff options
author | Jacques Garrigue <garrigue at math.nagoya-u.ac.jp> | 2009-10-22 08:45:21 (GMT) |
---|---|---|
committer | Jacques Garrigue <garrigue at math.nagoya-u.ac.jp> | 2009-10-22 08:45:21 (GMT) |
commit | 7d9e1dd495d4ba55d670de92dad383b821c574a0 (patch) | |
tree | c56effabd369906a3833d9c580e818f2c8d96b09 | |
parent | 910b9b83478a8dedf84c38591d187319e69d3b31 (diff) | |
download | ocaml-polyrec.zip ocaml-polyrec.tar.gz ocaml-polyrec.tar.bz2 |
l'exemple de Xavierpolyrec
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/polyrec@9390 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | testlabl/poly.ml | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/testlabl/poly.ml b/testlabl/poly.ml index e596290..1c6fb61 100644 --- a/testlabl/poly.ml +++ b/testlabl/poly.ml @@ -597,3 +597,16 @@ let zero = {f = `Int 0} ;; (* fails *) (* Yet another example *) let rec id : 'a. 'a -> 'a = fun x -> x and neg i b = (id (-i), id (not b));; + +(* De Xavier *) + +type t = A of int | B of (int*t) list | C of (string*t) list + +let rec transf f = function + | A x -> f x + | B l -> B (transf_alist f l) + | C l -> C (transf_alist f l) +and transf_alist : 'a. _ -> ('a*t) list -> ('a*t) list = fun f -> function + | [] -> [] + | (k,v)::tl -> (k, transf f v) :: transf_alist f tl +;; |