Module Relude_HList

type nil = unit;

Type of an empty HList

type cons('h, 't) = 'h => 't;

Type of a non-empty HList

type t('l) =
| HNil : t(nil)
| HCons('h, t('t)) : t(cons('h't))
;

HList.t is a heterogenous list type which can store a list of differently- typed values while retaining full type safety.

Originally this was using the special constructors [] and ::, but these seem to constantly conflict with the list versions in Pervasives.

let empty: t(nil);

HList.empty is the empty instance of an HList

let pure: 'a => t(cons('a, unit));

HList.pure lifts a pure value into a singleton HLlist.

let cons: 'h => t('t) => t(cons('h't));

Creates an HList from head and tail parts.

let uncons: t(cons('h't)) => ('h, t('t));

Splits an HList into head and tail parts.

let head: t(cons('h'a)) => 'h;

Returns the first element in a HList of 1 or more elements.

let tail: t(cons('a't)) => t('t);

Returns the tail of an HList of 1 or more elements.

let second: t(cons('acons('b'c))) => 'b;

Returns the second element of an HList of at least 2 elements

let third: t(cons('acons('bcons('c'd)))) => 'c;

Returns the third element of an HList of at least 3 elements

let fourth: t(cons('acons('bcons('ccons('d'e))))) => 'd;

Returns the fourth element of an HList of at least 4 elements

let fifth: t(cons('acons('bcons('ccons('dcons('e'f)))))) => 'e;

Returns the fifth element of an HList of at least 5 elements

let fromTuple2: ('a, 'b) => t(cons('acons('bnil)));

Creates an HList from a 2-tuple

let fromTuple3: ('a, 'b, 'c) => t(cons('acons('bcons('cnil))));

Creates an HList from a 3-tuple

let fromTuple4: ('a, 'b, 'c, 'd) => t(cons('acons('bcons('ccons('dnil)))));

Creates an HList from a 4-tuple

let fromTuple5: ('a, 'b, 'c, 'd, 'e) => t(cons('acons('bcons('ccons('dcons('enil))))));

Creates an HList from a 5-tuple

let toTuple2: t(cons('acons('bnil))) => ('a, 'b);

Converts an HList of 2 elements to a tuple

let toTuple3: t(cons('acons('bcons('cnil)))) => ('a, 'b, 'c);

Converts an HList of 3 elements to a tuple

let toTuple4: t(cons('acons('bcons('ccons('dnil))))) => ('a, 'b, 'c, 'd);

Converts an HList of 4 elements to a tuple

let toTuple5: t(cons('acons('bcons('ccons('dcons('enil)))))) => ('a, 'b, 'c, 'd, 'e);

Converts an HList of 4 elements to a tuple