Declarative JSON data manipulation for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

json: align json.mli with the [type t = json] convention

The implementation has used [t] as the canonical name for the JSON
value type for a while, but the .mli still referenced [json] in
many signatures (constructor types in [Value], encode/recode
return types, etc.). Switch the public surface to [t] so the
generated docs match the implementation and avoid the visual
"json or t?" ambiguity.

Also fix three [t] vs [codec] type annotations on [t2]/[t3]/[t4]
and [Object.case_codec] - those return codecs, not raw values,
and the .mli was wrong.

+14 -17
+14 -17
lib/json.mli
··· 586 586 ?dec:('a -> 'a -> 't2) -> 587 587 ?enc:('t2 -> int -> 'a) -> 588 588 'a codec -> 589 - 't2 t 589 + 't2 codec 590 590 (** [t2 ?dec ?enc t] maps JSON arrays with exactly 2 elements of type [t] to 591 591 value of type ['t2]. Decodes error if there are more elements. [enc v i] 592 592 must return the zero-based [i]th element. *) ··· 597 597 ?dec:('a -> 'a -> 'a -> 't3) -> 598 598 ?enc:('t3 -> int -> 'a) -> 599 599 'a codec -> 600 - 't3 t 600 + 't3 codec 601 601 (** [t3] is like {!t2} but for 3 elements. *) 602 602 603 603 val t4 : ··· 606 606 ?dec:('a -> 'a -> 'a -> 'a -> 't4) -> 607 607 ?enc:('t4 -> int -> 'a) -> 608 608 'a codec -> 609 - 't4 t 609 + 't4 codec 610 610 (** [t4] is like {!t2} but for 4 elements. *) 611 611 612 612 val tn : ?kind:string -> ?doc:string -> n:int -> 'a codec -> 'a array codec ··· 787 787 ?enc_omit:('tag -> bool) -> 788 788 ?enc_case:('cases -> ('cases, 'tag) Case.value) -> 789 789 string -> 790 - 'tag t -> 790 + 'tag codec -> 791 791 ('cases, 'tag) Case.t list -> 792 792 ('o, 'cases -> 'a) map -> 793 793 ('o, 'a) map ··· 1001 1001 type name = string node 1002 1002 (** The type for JSON member names. *) 1003 1003 1004 - type mem = name * json 1004 + type mem = name * t 1005 1005 (** The type for generic JSON object members. *) 1006 1006 1007 1007 and object' = mem list ··· 1022 1022 module Value : sig 1023 1023 (** {1:json JSON values} *) 1024 1024 1025 - type 'a cons = ?meta:Meta.t -> 'a -> json 1025 + type 'a cons = ?meta:Meta.t -> 'a -> t 1026 1026 (** The type for constructing JSON values from an OCaml value of type ['a]. 1027 1027 [meta] defaults to {!Meta.none}. *) 1028 1028 1029 - type t = json 1030 - (** See {!Json.val-json}. *) 1031 - 1032 1029 val meta : t -> Meta.t 1033 1030 (** [meta v] is the metadata of value [v]. *) 1034 1031 1035 - val set_meta : Meta.t -> t -> json 1032 + val set_meta : Meta.t -> t -> t 1036 1033 (** [set_meta m v] replaces [v]'s meta with [m]. *) 1037 1034 1038 - val copy_layout : t -> dst:json -> json 1035 + val copy_layout : t -> dst:json -> t 1039 1036 (** [copy_layout src ~dst] copies the layout of [src] and sets it on [dst] 1040 1037 using {!Meta.copy_ws}. *) 1041 1038 ··· 1148 1145 1149 1146 (** {1:encode Encode} *) 1150 1147 1151 - val encode : 'a codec -> 'a -> (json, string) result 1148 + val encode : 'a codec -> 'a -> (t, string) result 1152 1149 (** [encode t v] encodes a generic JSON value for [v] according to type [t]. 1153 1150 *) 1154 1151 1155 - val encode' : 'a codec -> 'a -> (json, Error.t) result 1152 + val encode' : 'a codec -> 'a -> (t, Error.t) result 1156 1153 (** [encode'] is like {!val-encode} but preserves the error structure. *) 1157 1154 1158 1155 (** {1:recode Recode} *) 1159 1156 1160 - val recode : 'a codec -> t -> (json, string) result 1157 + val recode : 'a codec -> t -> (t, string) result 1161 1158 (** [recode t v] decodes [v] with [t] and encodes it with [t]. *) 1162 1159 1163 - val recode' : 'a codec -> t -> (json, Error.t) result 1160 + val recode' : 'a codec -> t -> (t, Error.t) result 1164 1161 (** [recode'] is like {!val-recode} but preserves the error structure. *) 1165 1162 1166 - val update : 'a codec -> t -> json 1163 + val update : 'a codec -> t -> t 1167 1164 (** [update] is like {!val-recode} but raises {!Json.exception-Error}. *) 1168 1165 1169 1166 (** {1:errors Errors} *) ··· 1200 1197 val json_object : t codec 1201 1198 (** [json_object] represents JSON objects by their generic representation. *) 1202 1199 1203 - val json_mems : (json, json, mem list) Object.Mems.map 1200 + val json_mems : (t, json, mem list) Object.Mems.map 1204 1201 (** [json_mems] is a members map collecting unknown members into a generic JSON 1205 1202 object. See {{!page-cookbook.keeping}this example}. *) 1206 1203