Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >>
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >>
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/