camlspotter avatar camlspotter committed 76940c8

name fixes, and it is actually for version 1.1.0

Comments (0)

Files changed (9)

 1.1.0
 -------------
 
+INCOMPATIBLES    Sorry, lots of incompatibilities introduced but mainly name space fixes
+
+* Meta_conv.Internal.Make => Meta_conv.Coder.Make. 
+     Custom coder now needs to use less Internal.
+
+* Following name changes in Types.S:
+
+     Encode => Constr
+     Decode => Deconstr
+        In order to remove the confusion between the real decoders and encoders. 
+
+     Decode' => DeconstrDecoder
+
+     prim_decode => Helper.of_deconstr
+     generic_* => Helper.*
+
+     integer_of_float is now in Make functor as Helper.integer_of_float
+
 - Error.LocalException for locally bound exceptions for target specific errors
 
-- added Make(A).generic_hashtbl_of and Make(A).generic_of_hashtbl
-
 1.0.0
 -------------
 

json/json_conv.ml

 open Printf
 open Meta_conv.Open
-open Meta_conv.Internal
 open Json
 
 (* encoders ***************************************************************)
 
-include Meta_conv.Internal.Make(struct 
+include Meta_conv.Coder.Make(struct 
 
   type target = Json.t
 
       | Bool b -> fprintf ppf "%b" b
       | Null -> fprintf ppf "()"
 
-  module Encode = struct
+  module Constr = struct
     let tuple ts       = Array ts
     let variant tag = function
       | [] -> String tag
     let object_ = record
   end
 
-  module Decode = struct
+  module Deconstr = struct
   
     let tuple = function 
       | Array ts -> ts
 
 let failwithf fmt = kprintf (fun s -> raise (Failure s)) fmt
 
-let string_of_json = prim_decode (function
+let string_of_json = Helper.of_deconstr (function
   | String s -> s
   | _ -> failwith "string_of_json: String expected")
 
-let char_of_json = prim_decode (function
+let char_of_json = Helper.of_deconstr (function
   | String s when String.length s = 1 -> s.[0]
   | _ -> failwith "char_of_json: a char expected")
 
-let int_check name min max conv = prim_decode (function 
+let int_check name min max conv = Helper.of_deconstr (function 
   | Number n -> 
-      begin match integer_of_float min max conv n with
+      begin match Helper.integer_of_float min max conv n with
       | `Ok v -> v
       | `Error s -> failwithf "%s_of_json: %s" name s
       end
   let open Nativeint in
   int_check "nativeint" (to_float min_int) (to_float max_int) of_float
       
-let float_of_json = prim_decode (function
+let float_of_json = Helper.of_deconstr (function
   | Number n -> n
   | _ -> failwith "float_of_json: Number expected")
 
-let bool_of_json = prim_decode (function
+let bool_of_json = Helper.of_deconstr (function
   | Bool b -> b
   | _ -> failwith "bool_of_json: Bool expected")
 
-let unit_of_json = prim_decode (function
+let unit_of_json = Helper.of_deconstr (function
   | Null -> ()
   | _ -> failwith "unit_of_json: Null expected")
   
 let list_of_json f = 
-  generic_list_of (function Array xs -> Some xs | _ -> None) f
+  Helper.list_of (function Array xs -> Some xs | _ -> None) f
 
 let array_of_json f = 
-  generic_array_of (function Array xs -> Some xs | _ -> None) f
+  Helper.array_of (function Array xs -> Some xs | _ -> None) f
 
-let option_of_json f = generic_option_of 
+let option_of_json f = Helper.option_of 
   (function Null -> Some None | v -> Some (Some v))
   f
 
-let lazy_t_of_json d = generic_lazy_t_of (fun e -> raise (Error e)) d
+let lazy_t_of_json d = Helper.lazy_t_of (fun e -> raise (Error e)) d
 
-let json_of_mc_lazy_t = generic_of_mc_lazy_t
+let json_of_mc_lazy_t = Helper.of_mc_lazy_t
   
-let mc_lazy_t_of_json (d : 'a decoder) = (generic_mc_lazy_t_of d : ('a, Json.t) mc_lazy_t decoder)
+let mc_lazy_t_of_json (d : 'a decoder) = (Helper.mc_lazy_t_of d : ('a, Json.t) mc_lazy_t decoder)
 
 let json_of_mc_fields enc xs = Object (List.map (fun (name, a) -> (name, enc a)) xs)
-let mc_fields_of_json dec = generic_mc_fields_of (function Object js -> Some js | _ -> None) dec
+let mc_fields_of_json dec = Helper.mc_fields_of (function Object js -> Some js | _ -> None) dec
    open
    types
    internal
+   coder
 
 LIB = meta_conv
 
       let secondary_fields = List.filter (fun (k,_) -> List.mem k keys) secondary_fields in
       `Ok (Obj.obj o, secondary_fields)
   | `Error e -> `Error e
-
-(** { 6 Useful tool functions for writing encoders+decoders of primitive types } *)
-
-let integer_of_float min max conv n =
-  if floor n <> n then `Error "not an integer"
-  else if min <= n && n <= max then `Ok (conv n)
-  else `Error "overflow"
-
-let generic_list_of (type target) gets (d : (_,target) Decoder.t) ?(trace=[]) v = match gets v with
-  | None -> 
-      primitive_decoding_failure 
-        "Meta_conv.Internal.generic_list_of: listable expected" 
-        ~trace
-        v
-  | Some xs -> 
-      let trace = `Node v::trace in 
-      let module E = LocalException(struct type t = target end) in
-      E.catch begin fun () -> 
-        list_mapi (fun pos x -> E.exn (d ~trace:(`Pos pos :: trace)) x) xs
-      end () 
-
-let generic_array_of gets d ?trace v =
-  fmap Array.of_list (generic_list_of gets d ?trace v)
-
-let generic_option_of extract f ?trace v =
-  match extract v with 
-  | Some None -> `Ok None
-  | Some (Some v) -> f ?trace v >>= fun x -> `Ok (Some x)
-  | None -> 
-      primitive_decoding_failure 
-        "Meta_conv.Internal.generic_option_of: option expected"
-        ?trace v
-
-let generic_lazy_t_of (errorf : 'target Error.t -> 'exn) f ?trace:_ v = 
-  `Ok (lazy (
-    (* trace is reset to avoid leak *)
-    match f ?trace:None v with
-    | `Ok v -> v
-    | `Error e -> errorf e
-  ))
-
-let generic_of_mc_lazy_t e = fun v ->
-  match Lazy.force v with
-  | `Ok a -> e a
-  | `Error (_, a, _) -> a
-
-let generic_mc_lazy_t_of f ?trace:_ v = 
-  `Ok (lazy (f ?trace:None v)) (* trace is reset, to avoid leak *)
-
-let generic_mc_fields_of get_fields f ?(trace=[]) target =
-  let open Result in
-  match get_fields target with
-  | None -> primitive_decoding_failure "mc_fields expected" ~trace target
-  | Some fields ->
-      let trace = `Node target :: trace in
-      map (fun (name, target) -> f ?trace:(Some (`Field name :: trace)) target >>= fun host -> `Ok (name, host)) fields
-
-let prim_decode f = fun ?(trace=[]) v -> 
-  try `Ok (f v) with 
-  | Failure mes -> `Error (Primitive_decoding_failure mes, v, trace)
-
-(** { 6 Conv module type } *)
-
-module Make(A : Min) = struct
-  include A
-
-  exception Error of target Error.t
-
-  type 'a encoder = ('a, target) Encoder.t
-  type 'a decoder = ('a, target) Decoder.t
-  type 'a decoder_exn = ('a, target) Decoder.t_exn
-  
-  module Decode' = struct
-
-    let wrap f = fun ?(trace=([] : target Error.trace)) t -> try `Ok (f t) with exn -> `Error (Exception exn, t, trace)
-
-    let tuple ?trace x = wrap Decode.tuple ?trace x
-    let variant ?trace x = wrap Decode.variant ?trace x
-    let poly_variant ?trace x = wrap Decode.poly_variant ?trace x
-    let record ?trace x = wrap Decode.record ?trace x
-    let object_ ?trace x = wrap Decode.object_ ?trace x
-      
-    let wrap f = fun ?(trace=([] : target Error.trace)) t -> try f t with exn -> raise (Error (Exception exn, t, trace))
-
-    let tuple_exn ?trace x = wrap Decode.tuple ?trace x
-    let variant_exn ?trace x = wrap Decode.variant ?trace x
-    let poly_variant_exn ?trace x = wrap Decode.poly_variant ?trace x
-    let record_exn ?trace x = wrap Decode.record ?trace x
-    let object_exn ?trace x = wrap Decode.object_ ?trace x
-      
-  end
-
-  let exn f ?trace v = match f ?trace v with
-    | `Ok v -> v
-    | `Error e -> raise (Error e)
-
-  let throw e = raise (Error e)
-
-  let result f ?trace t = 
-    try `Ok (f ?trace t) with exn -> `Error (Error.Exception exn, t, ~?trace)
-
-  let from_Ok = function
-    | `Ok v -> v
-    | `Error e -> raise (Error e)
-
-  let format_error ppf (desc,_,_) = Error.format_desc ppf desc
-  let format_full_error = Error.format A.format
-
-  let format_with encoder ppf t = format ppf (encoder t)
-
-  (** Hashtbl coders via list *)
-
-  let generic_of_hashtbl of_list of_a of_b tbl =
-    of_list 
-      (fun x -> x)
-      (Hashtbl.fold (fun k v st -> Encode.tuple [of_a k; of_b v]::st) tbl [])
-
-  let generic_hashtbl_of list_of a_of b_of = fun ?trace v ->
-    let ab_of ?(trace=[]) v = 
-      Decode'.tuple ~trace v >>= function
-        | [a; b] -> 
-            a_of ?trace:(Some (`Pos 0 :: `Node v :: trace)) a >>= fun a ->
-            b_of ?trace:(Some (`Pos 0 :: `Node v :: trace)) b >>= fun b ->
-            `Ok (a,b)
-        | xs ->
-            `Error (Error.Wrong_arity (2, List.length xs, None), v, trace)
-    in
-    list_of ab_of ?trace v >>= fun abs ->
-    let tbl = Hashtbl.create 101 in (* CR jfuruse: size fixed *)
-    List.iter (fun (k,v) -> Hashtbl.add tbl k v) abs;
-    `Ok tbl
-
-end
 open Types
 open Open
 
-(** { 6 Conv module type interface } *)
-
-(** If you want to write an instance of meta_conv implementation, 
-    you define the following primitive encoders and decoders at least.
-*)
-module Make(A : Min) : S with type target = A.target
-
-(** { 6 Useful tool functions for writing encoders+decoders of primitive types } *)
-
-val integer_of_float : 
-  float              (** min value for 'int in float *)
-  -> float           (** max value for 'int in float *)
-  -> (float -> 'int) (** conversion *)
-  -> float           (** to convert *)
-  -> ('int, string) Result.t
-(** float to integer conversion with error checks *)
-
-val generic_list_of : 
-  ('target -> 'target list option) 
-  -> ('a, 'target) Decoder.t 
-  -> ('a list, 'target) Decoder.t
-(** typical list_of_<targe_type>. It takes a function to get a list from a target value *)
-
-val generic_array_of : 
-  ('target -> 'target list option) 
-  -> ('a, 'target) Decoder.t 
-  -> ('a array, 'target) Decoder.t
-(** typical array_of_<targe_type>. It takes a function to get a list from a target value  *)
-
-val generic_option_of : 
-  ('target -> 'target option option) 
-  -> ('a, 'target) Decoder.t 
-  -> ('a option, 'target) Decoder.t
-(** typical option_of_<targe_type>. 
-    It takes predicate to check the arg is a Some, None or something else.
-
-    Some (Some v) : Some for a target value v
-    Some None     : None
-    None :        : Error. Target value cannot have the option type
-*)
-
-val generic_lazy_t_of : 
-  ('target Error.t -> 'host) (** error handler *)
-  -> ('host, 'target) Decoder.t 
-  -> ('host lazy_t, 'target) Decoder.t
-(** typical lazy_t_of_<targe_type>. 
-    The decoding is done lazily. 
-    Error at the deferred decoding is handled by the error handler, 
-    normally it should raises <Target_conv>.Error exception.
-*)
-
-val generic_of_mc_lazy_t :
-  ('host, 'target) Encoder.t
-  -> (('host, 'target) mc_lazy_t, 'target) Encoder.t
-(** typical <targe_type>_of_mc_lazy_t *)
-
-val generic_mc_lazy_t_of : 
-  ('host, 'target) Decoder.t
-  -> (('host, 'target) mc_lazy_t, 'target) Decoder.t
-(** typical mc_lazy_t_of_<targe_type> 
-    The decoding is done lazily. 
-    Error at the lazy decoding is reported by the result monad.
-*)
- 
-val generic_mc_fields_of : 
-  ('target -> (string * 'target) list option)
-  -> ('host, 'target) Decoder.t
-  -> ((string * 'host) list, 'target) Decoder.t
-(** typical mc_fields_of_<targe_type> *)
-
-val prim_decode : ('target -> 'host) -> ('host, 'target) Decoder.t
-(** Convert a simple raw decoder of type ['target -> 'host] to [Decoder.t].
-    Error must be reported as [Failure s]. The other exceptions simply escape.
-*)
-
 (** { 6 Tools used by generated code } *)
 
 val field_assoc_exn : 
 (** List.map + List.filter *)
 
 val list_mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
+
+val (~?) : 'a list option -> 'a list
     on unimplemented primitve encoders fail.
 
     There are helper functions in Internal to implement these encoders,
-    see [generic_<tycon>_of] functions.
+    see [Helper.<tycon>_of] functions.
 *)
 val foobar_of_int       : int encoder
 val foobar_of_nativeint : nativeint encoder
     on unimplemented primitve decoders fail.
 
     There are helper functions in Internal to implement these decoders,
-    see [generic_of_<tycon>] functions.
+    see [Helper.of_<tycon>] functions.
 *)
 val int_of_foobar       : int decoder
 val nativeint_of_foobar : nativeint decoder
 
 (** Encoder and Decoder of Hashtbl.t 
 
-    They can be defined using the helper functions [generic_of_hashtbl] 
-    and [generic_hashtbl_of] using [('a * 'b) list] as actual encoding/decoding. 
-    The helpers are created by [Internal.Make(A)].
+    They can be defined using the helper functions [Helper.of_hashtbl] 
+    and [Helper.hashtbl_of] using [('a * 'b) list] as actual encoding/decoding. 
 
     Note that you must use the type name [hashtbl] instead of [Hashtbl.t],
     unless somehow you extend [Hashtbl] module with [Hashtbl.foobar_of_t]
+open Open
+
 (** { 6 Encoder } *)
 
 module Encoder = struct
 (** { 6 Decoder } *)
 
 module Decoder = struct
-  type ('host, 'target) t = ?trace:'target Error.trace -> 'target -> ('host, 'target Error.t) Result.t
-  type ('host, 'target) t_exn = ?trace:'target Error.trace -> 'target -> 'host
+  type ('host, 'target) t = 
+      ?trace:'target Error.trace -> 'target -> ('host, 'target Error.t) Result.t
+  (** Error is reported via Result.t *)
+
+  type ('host, 'target) t_exn = 
+      ?trace:'target Error.trace -> 'target -> 'host
+  (** Error is reported via a target specific exception *)
 end
 
 (** { 6 Conv module type } *)
   (** The target must be printable. *)  
   (** CR jfuruse: Is it called [print] instead? *)
 
-  module Encode : sig
+  module Constr : sig
     val tuple        : target list -> target
     val variant      : string -> target list -> target
     val poly_variant : string -> target list -> target
     val object_      : (string * target) list -> target
   end
   
-  module Decode : sig
+  module Deconstr : sig
 
     (** Primitive ADT decoders. They may raise exceptions. *)
 
   type 'a decoder     = ('a, target) Decoder.t
   type 'a decoder_exn = ('a, target) Decoder.t_exn
 
-  (* CR jfuruse: Bad name... *)      
-  (** Module [Decode'] is a wrapped version of [Decode] *)
-  module Decode' : sig
-    val tuple        : (target list) decoder
-    val variant      : (string * target list) decoder
-    val poly_variant : (string * target list) decoder
+  (** Auto generated decoders from Deconstr *)
+  module DeconstrDecoder : sig
+    val tuple        : target list              decoder
+    val variant      : (string * target list)   decoder
+    val poly_variant : (string * target list)   decoder
     val record       : ((string * target) list) decoder
     val object_      : ((string * target) list) decoder
 
-    val tuple_exn        : (target list) decoder_exn
-    val variant_exn      : (string * target list) decoder_exn
-    val poly_variant_exn : (string * target list) decoder_exn
+    val tuple_exn        : target list              decoder_exn
+    val variant_exn      : (string * target list)   decoder_exn
+    val poly_variant_exn : (string * target list)   decoder_exn
     val record_exn       : ((string * target) list) decoder_exn
     val object_exn       : ((string * target) list) decoder_exn
   end
 
   open Format
 
-  val format_error : formatter -> target Error.t -> unit
+  val format_error      : formatter -> target Error.t -> unit
   (** Format the error, without its trace *)
 
   val format_full_error : formatter -> target Error.t -> unit
   (** Format the error, with its full trace *)
 
-  val format_with : ('host -> target) -> Format.formatter -> 'host -> unit
+  val format_with : ('host -> target) -> formatter -> 'host -> unit
   (** Format host data using its encoder *)    
 
-  (** Hashtbl coders via list *)    
-  
-  val generic_of_hashtbl : 
-    (target encoder -> target list encoder) (** target_of_list *)
-    -> 'a encoder (** key encoder *)
-    -> 'b encoder (** value encoder *)
-    -> ('a,'b) Hashtbl.t encoder
+  module Helper : sig
+    (** { 6 Useful tool functions for writing encoders+decoders of primitive types } *)
+    
+    val integer_of_float : 
+      float              (** min value for 'int in float *)
+      -> float           (** max value for 'int in float *)
+      -> (float -> 'int) (** conversion *)
+      -> float           (** to convert *)
+      -> ('int, string) Result.t
+    (** float to integer conversion with error checks.
 
-  val generic_hashtbl_of : 
+        This is not target type dependent, but it is here for easier access.
+    *)
+    
+    val list_of : 
+      (target -> target list option) 
+      -> 'a decoder -> 'a list decoder
+    (** typical list_of_<targe_type>. It takes a function to get a list from a target value *)
+    
+    val array_of : 
+      (target -> target list option) 
+      -> 'a decoder -> 'a array decoder
+    (** typical array_of_<targe_type>. It takes a function to get a list from a target value  *)
+    
+    val option_of : 
+      (target -> target option option) 
+      -> 'a decoder -> 'a option decoder
+    (** typical option_of_<targe_type>. 
+        It takes predicate to check the arg is a Some, None or something else.
+    
+        Some (Some v) : Some for a target value v
+        Some None     : None
+        None :        : Error. Target value cannot have the option type
+    *)
+    
+    val lazy_t_of : 
+      (target Error.t -> 'a) (** error handler *)
+      -> 'a decoder -> 'a lazy_t decoder
+    (** typical lazy_t_of_<targe_type>. 
+        The decoding is done lazily. 
+        Error at the deferred decoding is handled by the error handler, 
+        normally it should raises <Target_conv>.Error exception.
+    *)
+    
+    val of_mc_lazy_t : 'a encoder -> ('a, target) mc_lazy_t encoder
+    (** typical <targe_type>_of_mc_lazy_t *)
+    
+    val mc_lazy_t_of : 'a decoder -> ('a, target) mc_lazy_t decoder
+    (** typical mc_lazy_t_of_<targe_type> 
+        The decoding is done lazily. 
+        Error at the lazy decoding is reported by the result monad.
+    *)
+     
+    val mc_fields_of : 
+      (target -> (string * target) list option)
+      -> 'a decoder -> (string * 'a) list decoder
+    (** typical mc_fields_of_<targe_type> *)
+    
+    val of_deconstr : (target -> 'a) -> 'a decoder
+    (** Convert a simple raw deconstr of type [target -> 'a] to ['a decoder].
+        Error must be reported as [Failure s]. The other exceptions simply escape.
+    *)
+
+    val of_hashtbl : 
+      (target encoder -> target list encoder) (** target_of_list *)
+      -> 'a encoder (** key encoder *)
+      -> 'b encoder (** value encoder *)
+      -> ('a,'b) Hashtbl.t encoder
+
+    val hashtbl_of : 
       (('a * 'b) decoder -> ('a * 'b) list decoder) (** list_of_target *)
       -> 'a decoder (** key encoder *)
       -> 'b decoder (** value encoder *)
       -> ('a, 'b) Hashtbl.t decoder
+
+  end
+
 end

ocaml/ocaml_conv.ml

 open Meta_conv.Open
 open Meta_conv.Types
-open Meta_conv.Internal
 open Ocaml
 
-include Meta_conv.Internal.Make(struct
+include Meta_conv.Coder.Make(struct
   type target = Ocaml.t
   let format fmt = Ocaml.format fmt
 
-  module Encode = struct
+  module Constr = struct
     let tuple ts = Tuple ts
     let variant tag ts = Variant (tag, ts)
     let poly_variant tag ts = Poly_variant (tag, ts)
     let object_ fields = Object fields
   end
 
-  module Decode = struct
+  module Deconstr = struct
     let tuple = function 
       | Tuple ts -> ts
       | _ -> failwith "Tuple expected for tuple"
 
 let ocaml_of_mc_fields f fields = Record ( List.map (fun (k,v) -> k, f v) fields )
 
-let unit_of_ocaml = prim_decode (function
+let unit_of_ocaml = Helper.of_deconstr (function
   | Unit -> ()
   | _ -> failwith "unit_of trace: Unit expected")
   
-let bool_of_ocaml = prim_decode (function
+let bool_of_ocaml = Helper.of_deconstr (function
   | Bool b -> b
   | _ -> failwith "bool_of trace: Bool expected")
 
-let string_of_ocaml = prim_decode (function
+let string_of_ocaml = Helper.of_deconstr (function
   | String s -> s
   | _ -> failwith "string_of trace: String expected")
 
-let char_of_ocaml = prim_decode (function
+let char_of_ocaml = Helper.of_deconstr (function
   | Char c -> c
   | _ -> failwith "char_of trace: a char expected")
 
-let int32_of_ocaml = prim_decode (function
+let int32_of_ocaml = Helper.of_deconstr (function
   | Int32 n -> n
   | _ -> failwith "int32_of trace: int32 expected")
 
-let int64_of_ocaml = prim_decode (function
+let int64_of_ocaml = Helper.of_deconstr (function
   | Int64 n -> n
   | _ -> failwith "int64_of trace: int64 expected")
 
-let float_of_ocaml = prim_decode (function
+let float_of_ocaml = Helper.of_deconstr (function
   | Float n -> n
   | _ -> failwith "float_of trace: float expected")
 
-let list_of_ocaml f = generic_list_of (function List xs -> Some xs | _ -> None) f
+let list_of_ocaml f = Helper.list_of (function List xs -> Some xs | _ -> None) f
 
-let array_of_ocaml f = generic_array_of (function Array xs -> Some xs | _ -> None) f
+let array_of_ocaml f = Helper.array_of (function Array xs -> Some xs | _ -> None) f
 
-let option_of_ocaml f = generic_option_of (function
+let option_of_ocaml f = Helper.option_of (function
   | Variant ("None", []) -> Some None 
   | Variant ("Some", [v]) -> Some (Some v)
   | _ -> None) f
 
 let lazy_t_of_ocaml (d : ('a, Ocaml.t) Decoder.t) : ('a lazy_t, Ocaml.t) Decoder.t = 
-  generic_lazy_t_of (fun (e : Ocaml.t Meta_conv.Error.t) -> raise (Error e)) d
+  Helper.lazy_t_of (fun (e : Ocaml.t Meta_conv.Error.t) -> raise (Error e)) d
 
 
 (** Arch dependent enc/decoders *)
   let ocaml_of_int n = Int31 n
   let ocaml_of_nativeint n = Nativeint32 (Nativeint.to_int32 n)
 
-  let int_of_ocaml = prim_decode (function
+  let int_of_ocaml = Helper.of_deconstr (function
     | Int31 n -> n
     | Int63 n ->
         let n' = Int64.to_int n in
         else n'
     | _ -> failwith "int_of_ocaml: int expected")
 
-  let nativeint_of_ocaml = prim_decode (function
+  let nativeint_of_ocaml = Helper.of_deconstr (function
     | Nativeint32 n -> Nativeint.of_int32 n
     | Nativeint64 n ->
         let n' = Int64.to_nativeint n in
   let ocaml_of_int n = Int63 (Int64.of_int n)
   let ocaml_of_nativeint n = Nativeint64 (Int64.of_nativeint n)
 
-  let int_of_ocaml = prim_decode (function
+  let int_of_ocaml = Helper.of_deconstr (function
     | Int31 n -> n
     | Int63 n -> (Int64.to_int n)
     | _ -> failwith "int_of_ocaml: int expected")
 
-  let nativeint_of_ocaml = prim_decode (function
+  let nativeint_of_ocaml = Helper.of_deconstr (function
     | Nativeint32 n -> Nativeint.of_int32 n
     | Nativeint64 n -> Int64.to_nativeint n
     | _ -> failwith "int_of_ocaml: nativeint expected")
 
 include (val arch)
 
-let ocaml_of_hashtbl x = generic_of_hashtbl ocaml_of_list x
+let ocaml_of_hashtbl x = Helper.of_hashtbl ocaml_of_list x
 
-let hashtbl_of_ocaml x = generic_hashtbl_of list_of_ocaml x
+let hashtbl_of_ocaml x = Helper.hashtbl_of list_of_ocaml x

pa/pa_meta_conv.ml

         let ids = mk_idents "__x" (List.length ctyps) in
         Gen.abstract loc [ create_patt_tuple (List.map patt_of_id ids) ]
           (create_expr_app 
-           <:expr< $id:module_path$.Encode.tuple >>
+           <:expr< $id:module_path$.Constr.tuple >>
              [create_list (List.map2 (fun id ctyp ->
                <:expr< $gen_ctyp ctyp$ $expr_of_id id$ >>
              ) ids ctyps)])
         | [exp] -> <:match_case< $ patt $ -> $ exp $ >>
         | _ -> 
             let exp = create_expr_app
-              <:expr< $id:module_path$.Encode.tuple >>
+              <:expr< $id:module_path$.Constr.tuple >>
               [ create_list args ]
             in
             <:match_case< $ patt $ -> $ exp $ >>
 
   and gen_variants ?top _loc cases = 
     gen_gen_variants 
-      <:expr< $id:module_path$.Encode.poly_variant >>
+      <:expr< $id:module_path$.Constr.poly_variant >>
       (fun loc idstr -> <:patt@loc< `$idstr$ >>) 
       ?top _loc cases
 
     in
     let _annot = interprete_record_type_name_annotation tyd_loc name in 
     let decode_exn = match kind with
-      | `Record -> <:expr< $id:module_path$.Decode'.record_exn >>
-      | `Object -> <:expr< $id:module_path$.Decode'.object_exn >>
+      | `Record -> <:expr< $id:module_path$.DeconstrDecoder.record_exn >>
+      | `Object -> <:expr< $id:module_path$.DeconstrDecoder.object_exn >>
     in
     let fields = List.fold_right (fun (loc, lab_id, ctyp) fields ->
       let f = gen_ctyp (strip_field_flags ctyp) in
 
   and gen_object ?top _loc field_types =
     let accessor lab_id = <:expr< __v#$name_of_ident lab_id$ >> in
-    let creator = <:expr< $id:module_path$.Encode.object_ >> in
+    let creator = <:expr< $id:module_path$.Constr.object_ >> in
     gen_gen_record `Object accessor creator ?top _loc field_types
 
   let sum tyd_loc name params loc cases =
     let cases = List.map (fun (a, id, b) -> (a, name_of_ident id, b)) cases in
     let e = gen_gen_variants
-      <:expr< $id:module_path$.Encode.variant >>
+      <:expr< $id:module_path$.Constr.variant >>
         (fun loc idstr -> <:patt@loc< $uid:idstr$ >>) 
         ~top:(tyd_loc, name)
         loc cases
     
   let record tyd_loc name params _loc field_types = 
     let accessor lab_id = <:expr< __v.$id:lab_id$ >> in
-    let creator = <:expr< $id:module_path$.Encode.record  >> in
+    let creator = <:expr< $id:module_path$.Constr.record  >> in
     let e = gen_gen_record `Record accessor creator ~top:(tyd_loc, name) _loc field_types in
     [ dcl tyd_loc name params e ]
     
         in
         let binds = binds ids exps tup in
         <:expr< fun ?trace:(__t=[]) __v -> 
-          match $id:module_path$.Decode'.tuple ~trace:__t __v with
+          match $id:module_path$.DeconstrDecoder.tuple ~trace:__t __v with
           | `Ok $pat$ -> 
               let __t = `Node __v :: __t in
               $binds$
       in
       let cases = List.map case cases @ [ default ] in
       let decode = match kind with
-        | `Variant -> <:expr< $id:module_path$.Decode'.variant >>
-        | `Poly_variant -> <:expr< $id:module_path$.Decode'.poly_variant >>
+        | `Variant -> <:expr< $id:module_path$.DeconstrDecoder.variant >>
+        | `Poly_variant -> <:expr< $id:module_path$.DeconstrDecoder.poly_variant >>
       in
       <:expr< fun ?trace:(__t=[]) __v -> 
         let __name = $str:name$ in
       let gen_embeded (lab_id, (mode, ctyp)) =
         (* Very dirty trick + inefficient *) 
         let encoder = match kind with
-          | `Record -> <:expr< $id:module_path$.Encode.record >>
-          | `Object -> <:expr< $id:module_path$.Encode.object_ >>
+          | `Record -> <:expr< $id:module_path$.Constr.record >>
+          | `Object -> <:expr< $id:module_path$.Constr.object_ >>
         in
         match mode with
         | `Embeded -> 
     in
 
     let decode = match kind with
-      | `Record -> <:expr< $id:module_path$.Decode'.record >>
-      | `Object -> <:expr< $id:module_path$.Decode'.object_ >>
+      | `Record -> <:expr< $id:module_path$.DeconstrDecoder.record >>
+      | `Object -> <:expr< $id:module_path$.DeconstrDecoder.object_ >>
     in
 
     <:expr< fun ?trace:(__t=[]) __v -> 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.