package records

  1. Overview
  2. Docs

Layouts

type 's layout

The representation of record types. 's is usually a phantom type. Two interfaces are provided for creating layouts, in Unsafe and Safe.

type ('a, 's) field

A field of type 'a within a 's layout.

  • deprecated Please use Field.t instead
val field_name : ('a, 's) field -> string

Get the name of the field (as passed to field).

  • deprecated Please use Field.name instead
val field_type : ('a, 's) field -> 'a Type.t

Get the type of the field (as passed to field).

  • deprecated Please use Field.typ instead
val declare : string -> 's layout

Create a new layout with the given name.

  • deprecated This function has been moved to Record.Unsafe
val field : 's layout -> string -> 'a Type.t -> ('a, 's) field

Add a field to a layout. This modifies the layout and returns the field.

  • deprecated This function has been moved to Record.Unsafe
val seal : 's layout -> unit

Make the layout unmodifiable. It is necessary before constructing values.

  • deprecated This function has been moved to Record.Unsafe
exception ModifyingSealedStruct of string

Raised by field or seal if layout has already been sealed.

val layout_name : 's layout -> string

Get the name that was given to a layout.

  • deprecated This function has been moved to Record.Unsafe
val layout_id : 's layout -> 's Polid.t

Get the unique identifier given to a layout.

  • deprecated This function has been moved to Record.Unsafe

Records

type 's t = {
  1. layout : 's layout;
  2. content : 's content;
}

The representation of record values.

and 's content
val make : 's layout -> 's t

Allocate a record of a given layout, with all fields initially unset.

  • deprecated This function has been moved to Record.Unsafe
val get_layout : 'a t -> 'a layout

Get the layout of a record.

val layout_type : 'a layout -> 'a t Type.t

Get the Type.t representation of a layout.

  • deprecated This function has been moved to Record.Util
val declare0 : name:string -> 's layout

Shortcut to build a layout with no fields.

  • deprecated This function has been moved in Record.Util
val declare1 : name:string -> f1_name:string -> f1_type:'a Type.t -> 's layout * ('a, 's) field

Shortcut to build a layout with 1 field.

  • deprecated This function has been moved in Record.Util
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.

  • deprecated This function has been moved in Record.Util
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.

  • deprecated This function has been moved in Record.Util
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.

  • deprecated This function has been moved in Record.Util
exception AllocatingUnsealedStruct of string

Raised by make when the corresponding layout has not been sealed.

val get : 's t -> ('a, 's) field -> 'a

Get the value of a field.

val set : 's t -> ('a, 's) field -> 'a -> unit

Set the value of a field.

exception UndefinedField of string

Raised by get if the field was not set.

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.

  • deprecated Use to_yojson instead
val of_json : 'a layout -> Yojson.Basic.json -> 'a t

Convert a JSON value into a given schema.

  • deprecated Use of_yojson instead
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.

OCaml

Innovation. Community. Security.