Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 =
    function
      | [] -> sofar
      | (name,constructors) :: ys ->
      iter <:str_item< $sofar$ and $lid:name$ = $constructor$  >> ys
  in
    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