* defining recursive types with camlp4
@ 2009-06-14 21:10 Jacques Le Normand
2009-06-14 22:11 ` [Caml-list] " blue storm
0 siblings, 1 reply; 2+ messages in thread
From: Jacques Le Normand @ 2009-06-14 21:10 UTC (permalink / raw)
To: caml-list caml-list
[-- Attachment #1: Type: text/plain, Size: 760 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 926 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] defining recursive types with camlp4
2009-06-14 21:10 defining recursive types with camlp4 Jacques Le Normand
@ 2009-06-14 22:11 ` blue storm
0 siblings, 0 replies; 2+ messages in thread
From: blue storm @ 2009-06-14 22:11 UTC (permalink / raw)
To: Jacques Le Normand; +Cc: caml-list caml-list
On Sun, Jun 14, 2009 at 11:10 PM, Jacques Le
Normand<rathereasy@gmail.com> wrote:
> how would I go about writing such a function?
The "... and ..." multiple-declaration isn't at the str_item level but
at the ctyp level. You should use <:ctyp< $..$ and $...$ >>. Moreover,
it appears that the type declaration node in the AST (Ast.TyDcl) does
not have a quotation syntax : <:str_item< type $..$ = $...$ >> won't
work.
let type_chain _loc lst =
let decl (name, constructors) = Ast.TyDcl(_loc, name, [],
constructors, []) in
<:str_item< type $Ast.tyAnd_of_list (List.map decl lst)$ >>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-06-14 22:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-14 21:10 defining recursive types with camlp4 Jacques Le Normand
2009-06-14 22:11 ` [Caml-list] " blue storm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox