From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Joel Reymont" <joelr1@gmail.com>
Cc: "Caml List" <caml-list@inria.fr>
Subject: Re: [Caml-list] camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >>
Date: Tue, 1 May 2007 09:26:51 +0200 [thread overview]
Message-ID: <cd67f63a0705010026h744039f1u1e5c215b01b96d89@mail.gmail.com> (raw)
In-Reply-To: <85C23368-5DC3-4ECB-BEBA-EB98E5140E33@gmail.com>
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
prev parent reply other threads:[~2007-05-01 7:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-30 21:52 Joel Reymont
2007-05-01 7:26 ` Nicolas Pouillard [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd67f63a0705010026h744039f1u1e5c215b01b96d89@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@inria.fr \
--cc=joelr1@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).