package orec

  1. Overview
  2. Docs

Module Orec.DefaultSource

Default namespace for record fields

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

Bijection record

Bijection inversion

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

Bijection inversion

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

Bijection composition

Sourcetype t

The type of record within the namespace

Sourcetype 'info field_action

The type of a field getter or updater

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

Aliases for the type of fields

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

The empty record

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.

Sourceval 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.

Sourceval new_field_mut : unit -> 'ty mut_field
Sourceval new_field_exn : unit -> 'ty exn_field
Sourceval new_field_exn_mut : unit -> 'ty exn_mut_field
Sourceval 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 }

Sourceval (^=) : < x : 'ty.. > get -> 'ty -> (_ Type_data.const, t) update
Sourceval 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

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

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

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

Copy a mutable field

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

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

Sourceval (.%{}) : 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
Sourceval (.%{}<-) : t -> < x : 'ty ; mut : Type_data.mut.. > get -> 'ty -> unit
Sourceval get : < ret : 'ret.. > get -> t -> 'ret

non-operator version of get,set and update

Sourceval update : (Type_data.any, t) update -> t -> t
Sourceval set : < x : 'ty ; mut : Type_data.mut.. > get -> 'ty -> t -> unit
Sourceval 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

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

Operator version of transmute

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

exception based version of transmute

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

Operator version of transmute_exn