Version française
Home     About     Download     Resources     Contact us    
Browse thread
Upgrading sexplib-2.7.0 to camlp4 3.10
[ 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: Re: Upgrading sexplib-2.7.0 to camlp4 3.10
RfTag is gone, apparently. How do you process variants then?

The only reference to constructors I could find is with_constr in  
Camlp4Ast.partial.ml. It's applicable to modules, apparently.

The original code is attached below.

    Thanks, Joel

---

   and sexp_of_variants_loop _loc acc = function
     | RfTag (cnstr, _, []) ->
         (
           <:patt< `$cnstr$ >>,
           None,
           <:expr< Sexplib.Sexp.Atom $str:cnstr$ >>
         ) :: acc
     | RfTag (cnstr, _, tps) ->
         let fps = List.map (sexp_of_type _loc) tps in
         let bindings, patts, vars = Gen.mk_bindings _loc fps in
         let arg_patt = tuplify_patts _loc patts in
         let cnstr_expr = <:expr< Sexplib.Sexp.Atom $str:cnstr$ >> in
         (
           <:patt< `$cnstr$ $arg_patt$ >>,
           None,
           <:expr<
             let $list:bindings$ in
             Sexplib.Sexp.List $Gen.mk_expr_lst _loc (cnstr_expr ::  
vars)$
           >>
         ) :: acc
     | RfInh (TyVrn (_loc, row_fields, _)) ->
         List.fold_left (sexp_of_variants_loop _loc) acc row_fields
     | RfInh tp ->
         let tp_path, call =
           match tp with
           | <:ctyp< $tp1$ $tp2$ >> ->
               let fp1 = sexp_of_type _loc tp1 in
               let fp2 = sexp_of_type _loc tp2 in
               let tp_path = List.rev (Gen.tp_path (get_appl_path  
_loc tp1)) in
               let expr = sexp_of_appl_fun _loc fp1 fp2 in
               tp_path, expr
           | _ ->
               let tp_path = Gen.tp_path tp in
               match tp_path with
               | tn :: path -> tp_path, mk_abst_call _loc tn path
               | [] -> assert false  (* impossible *)
         in
         (
           <:patt< (#$tp_path$ as v) >>,
           None,
           <:expr< $call$ v >>
         ) :: acc

   and sexp_of_variant _loc row_fields =
     `Match (
       List.rev (List.fold_left (sexp_of_variants_loop _loc) []  
row_fields))

--
http://wagerlabs.com/