Library
Module
Module type
Parameter
Class
Class type
Layouts
The representation of record types. 's
is usually a phantom type. Two interfaces are provided for creating layouts, in Unsafe
and Safe
.
val field_name : ('a, 's) field -> string
Get the name of the field (as passed to field
).
val declare : string -> 's layout
Create a new layout with the given name.
Add a field to a layout. This modifies the layout and returns the field.
val seal : 's layout -> unit
Make the layout unmodifiable. It is necessary before constructing values.
val layout_name : 's layout -> string
Get the name that was given to a layout.
Records
val declare0 : name:string -> 's layout
Shortcut to build a layout with no fields.
Shortcut to build a layout with 1 field.
val declare2 :
name:string ->
f1_name:string ->
f1_type:'a1 Type.t ->
f2_name:string ->
f2_type:'a2 Type.t ->
's layout * ('a1, 's) field * ('a2, 's) field
Shortcut to build a layout with 2 fields.
val declare3 :
name:string ->
f1_name:string ->
f1_type:'a1 Type.t ->
f2_name:string ->
f2_type:'a2 Type.t ->
f3_name:string ->
f3_type:'a3 Type.t ->
's layout * ('a1, 's) field * ('a2, 's) field * ('a3, 's) field
Shortcut to build a layout with 3 fields.
val declare4 :
name:string ->
f1_name:string ->
f1_type:'a1 Type.t ->
f2_name:string ->
f2_type:'a2 Type.t ->
f3_name:string ->
f3_type:'a3 Type.t ->
f4_name:string ->
f4_type:'a4 Type.t ->
's layout
* ('a1, 's) field
* ('a2, 's) field
* ('a3, 's) field
* ('a4, 's) field
Shortcut to build a layout with 4 fields.
Raised by make
when the corresponding layout has not been sealed.
module Type : sig ... end
module Field : sig ... end
module Polid : sig ... end
module Unsafe : sig ... end
module Safe : sig ... end
Miscellaneous
val to_json : 'a t -> Yojson.Basic.json
Convert a record to JSON.
val of_json : 'a layout -> Yojson.Basic.json -> 'a t
Convert a JSON value into a given schema.
val to_yojson : 'a t -> Yojson.Safe.json
Convert a record to JSON.
val of_yojson :
'a layout ->
Yojson.Safe.json ->
[ `Ok of 'a t | `Error of string ]
Convert a JSON value into a given schema.
module Util : sig ... end
val equal : 'a layout -> 'b layout -> ('a, 'b) Polid.equal
Equality predicate.
val format : Format.formatter -> 'a t -> unit
Print the JSON representation of a record to a formatter.