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('a, cons('b, 'c))) => 'b;

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

let third: t(cons('a, cons('b, cons('c, 'd)))) => 'c;

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

let fourth: t(cons('a, cons('b, cons('c, cons('d, 'e))))) => 'd;

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

let fifth: t(cons('a, cons('b, cons('c, cons('d, cons('e, 'f)))))) => 'e;

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

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

Creates an HList from a 2-tuple

let fromTuple3: ('a, 'b, 'c) => t(cons('a, cons('b, cons('c, nil))));

Creates an HList from a 3-tuple

let fromTuple4: ('a, 'b, 'c, 'd) => t(cons('a, cons('b, cons('c, cons('d, nil)))));

Creates an HList from a 4-tuple

let fromTuple5: ('a, 'b, 'c, 'd, 'e) => t(cons('a, cons('b, cons('c, cons('d, cons('e, nil))))));

Creates an HList from a 5-tuple

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

Converts an HList of 2 elements to a tuple

let toTuple3: t(cons('a, cons('b, cons('c, nil)))) => ('a, 'b, 'c);

Converts an HList of 3 elements to a tuple

let toTuple4: t(cons('a, cons('b, cons('c, cons('d, nil))))) => ('a, 'b, 'c, 'd);

Converts an HList of 4 elements to a tuple

let toTuple5: t(cons('a, cons('b, cons('c, cons('d, cons('e, nil)))))) => ('a, 'b, 'c, 'd, 'e);

Converts an HList of 4 elements to a tuple