English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
defining recursive types with camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-06-14 (21:10)
From: Jacques Le Normand <rathereasy@g...>
Subject: defining recursive types with camlp4
Hello ocaml list,
I have a list of name constructor pairs and from that list I want to define
a set of recursive types. I've written the following function:

let type_chain _loc  lst =
  let rec iter sofar =
      | [] -> sofar
      | (name,constructors) :: ys ->
      iter <:str_item< $sofar$ and $lid:name$ = $constructor$  >> ys
    match lst with
    (name,constructors) :: ys ->
      iter <:str_item< type $lid:name$ = $constructors$ >> ys
      | _ -> raise (Failure "no types defined")

which, unfortunately, fails to type check with the error:

While expanding quotation "str_item" in a position of "expr":
  Parse error: illegal begin of quotation of structure item

how would I go about writing such a function?

--Jacques L