* camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >>
@ 2007-04-30 21:52 Joel Reymont
2007-05-01 7:26 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 2+ messages in thread
From: Joel Reymont @ 2007-04-30 21:52 UTC (permalink / raw)
To: Caml List
Consider the following function. My understanding is that for, say,
Hashtbl.t it should return a list of types where the 1st element
represents "t" and the second represents "Hashtbl".
(* [tp_path tp] takes a type. @return a module path (list of strings)
denoting this type. *)
let rec tp_path = function
| <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
| <:ctyp< $tp1$ . $tp2$ >> ->
(match tp_path tp2 with [n] -> n | _ -> assert false) ::
tp_path tp1
| _ -> invalid_arg "tp_path"
Nicolas suggested the following approach which doesn't work because
tp1 and tp2 become idents. There's a function to convert from ctyp to
ident but I could not find the opposite from searching the camlp4
source tree.
let rec tp_path = function
| <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
| <:ctyp< $id:id$ >> ->
(match id with
| <:ident< $tp1$ . $tp2$ >> ->
(match tp_path tp2 with [n] -> n | _ -> assert false) ::
tp_path tp1
| _ -> invalid_arg "tp_path")
| _ -> invalid_arg "tp_path"
Since Hashtbl.t is a valid type, there should be a camlp4 ctyp
pattern to match it, no?
Am I missing something obvious?
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >>
2007-04-30 21:52 camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >> Joel Reymont
@ 2007-05-01 7:26 ` Nicolas Pouillard
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 7:26 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 4/30/07, Joel Reymont <joelr1@gmail.com> wrote:
> Consider the following function. My understanding is that for, say,
> Hashtbl.t it should return a list of types where the 1st element
> represents "t" and the second represents "Hashtbl".
>
> (* [tp_path tp] takes a type. @return a module path (list of strings)
> denoting this type. *)
> let rec tp_path = function
> | <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
> | <:ctyp< $tp1$ . $tp2$ >> ->
> (match tp_path tp2 with [n] -> n | _ -> assert false) ::
> tp_path tp1
> | _ -> invalid_arg "tp_path"
>
> Nicolas suggested the following approach which doesn't work because
> tp1 and tp2 become idents. There's a function to convert from ctyp to
> ident but I could not find the opposite from searching the camlp4
> source tree.
>
> let rec tp_path = function
> | <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
> | <:ctyp< $id:id$ >> ->
> (match id with
> | <:ident< $tp1$ . $tp2$ >> ->
> (match tp_path tp2 with [n] -> n | _ -> assert false) ::
> tp_path tp1
> | _ -> invalid_arg "tp_path")
> | _ -> invalid_arg "tp_path"
>
> Since Hashtbl.t is a valid type, there should be a camlp4 ctyp
> pattern to match it, no?
>
> Am I missing something obvious?
To see how is represented something:
$ camlp4of -str '<:ctyp< Hashtbl.t >>'
Ast.TyId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Hashtbl"), Ast.IdLid (_loc, "t")))
So the function tp_path doesn't need to recurse on types since there
is only one node which is TyId(_,_) -> <:ctyp< $id:_$ >>
let tp_path = function
| <:ctyp< $id:path$ >> ->
let rec loop =
function
| <:ident< $i1$.$i2$ >> -> ...
| ...
in loop path
| _ -> fail....
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-05-01 7:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-30 21:52 camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >> Joel Reymont
2007-05-01 7:26 ` [Caml-list] " Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox