package orec

  1. Overview
  2. Docs

Create a new namespace

Parameters

Signature

include Bijection.S
type ('a, 'b) bijection = {
  1. to_ : 'a -> 'b;
  2. from : 'b -> 'a;
}

Bijection record

Bijection inversion

val flip : ('a, 'b) bijection -> ('b, 'a) bijection

Bijection inversion

val (%) : ('a, 'b) bijection -> ('c, 'a) bijection -> ('c, 'b) bijection

Bijection composition

type t

The type of record within the namespace

type 'info field_action

The type of a field getter or updater

type 'info get = (('a, 'mut) Type_data.getter * 'res) field_action constraint 'info = < x : 'a ; mut : 'mut ; ret : 'res >

Aliases for the type of fields

type 'a field = < x : 'a ; mut : Type_data.imm ; ret : 'a option > get
type 'a mut_field = < x : 'a ; mut : Type_data.mut ; ret : 'a option > get
type 'a exn_field = < x : 'a ; mut : Type_data.imm ; ret : 'a > get
type 'a exn_mut_field = < x : 'a ; mut : Type_data.mut ; ret : 'a > get
type ('param, 't) update = ('param Type_data.updater * 't) field_action
val empty : t

The empty record

val create : (Type_data.only Type_data.const, t) update list -> t

Create a new open record from a list of field updater : create [ field1 ^= value1; field2 ^= value2; ... ] Only const updater make sense in this context, since there is no fields present.

val new_field : unit -> 'ty field

Creation of a new fields. Note that the type 'ty would be weakly polymorphic once the field created. However, in this specific use case, it seems reasonable to annotate the field type by using one of the field type aliases.

val new_field_mut : unit -> 'ty mut_field
val new_field_exn : unit -> 'ty exn_field
val new_field_exn_mut : unit -> 'ty exn_mut_field
val put : < x : 'ty.. > get -> 'ty -> (_ Type_data.const, t) update

Constant field updater: record.{ field ^= v } sets the value of field to v and is equivalent to record.{ put field v }

val (^=) : < x : 'ty.. > get -> 'ty -> (_ Type_data.const, t) update
val fmap : < x : 'ty.. > get -> ('ty -> 'ty) -> ('a Type_data.fn, t) update

Field map: record.{field |= f } or record.{ fmap field f } are equivalent to record.{ field ^= fmap f record.{field} } if the field exists, and do nothing otherwise

val (|=) : < x : 'ty.. > get -> ('ty -> 'ty) -> ('a Type_data.fn, t) update

Field combinator orec.%{ x & y } is orec.%{x}.%{y}

val copy : < x : 'ty ; mut : Type_data.mut.. > get -> ('a Type_data.fn, t) update

Copy a mutable field

val delete : < .. > get -> ('a Type_data.del, t) update

Delete a field, if the field does not exist, do nothing

val (.%{}) : t -> (_ * 'ret) field_action -> 'ret

(.%{} ) operator:

  • record.%{field} returns the value of the field
  • record.%{field ^= value} returns a functional update of record
  • record.%{field |= f} is equivalent to record.{ field ^= f record.{field} }
  • record.%{delete field} returns an updated version of record without this field
val (.%{}<-) : t -> < x : 'ty ; mut : Type_data.mut.. > get -> 'ty -> unit
val get : < ret : 'ret.. > get -> t -> 'ret

non-operator version of get,set and update

val update : (Type_data.any, t) update -> t -> t
val set : < x : 'ty ; mut : Type_data.mut.. > get -> 'ty -> t -> unit
val transmute : < x : 'a ; mut : 'm.. > as 'x get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b option > get

Use the type equality implied by the bijection 'a⟺'b to create a new 'b field getter from a 'a field getter. The new field getter uses option access

val (@:) : < x : 'a ; mut : 'm.. > as 'x get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b option > get

Operator version of transmute

val transmute_exn : < x : 'a ; mut : 'm.. > as 'x get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b > get

exception based version of transmute

val (@:!) : < x : 'a ; mut : 'm.. > as 'x get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b > get

Operator version of transmute_exn

OCaml

Innovation. Community. Security.