API / Belt / Id

You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest API docs here.

(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)

Id

Provide utilities to create identified comparators or hashes for data structures used below.

It creates a unique identifier per module of functions so that different data structures with slightly different comparison functions won't mix.

hash

RE
type hash('a, 'id);

Its runtime represenation is a hash function, but signed with a type parameter, so that different hash functions type mismatch.

eq

RE
type eq('a, 'id);

Its runtime represenation is an eq function, but signed with a type parameter, so that different hash functions type mismatch.

cmp

RE
type cmp('a, 'id);

Its runtime representation is a cmp function, but signed with a type parameter, so that different hash functions type mismatch.

Comparable

RE
module type Comparable { type identity; type t; let cmp: BeltId.cmp(t, identity); }

comparable

RE
type ('key,'id) comparable = (module BeltId.Comparable with type identity = 'id and type t = 'key)

is a module of functions, here it only includes cmp.

Unlike normal functions, when created, it comes with a unique identity (guaranteed by the type system).

It can be created using function Belt_Id.comparableU or Belt_Id.comparable.

The idea of a unique identity when created is that it makes sure two sets would type mismatch if they use different comparison function

MakeComparableU

RE
module MakeComparableU: (M: {type t; let cmp: [@bs] ((t, t) => int);}) => Comparable with type t = M.t;

MakeComparable

RE
module MakeComparable: (M: {type t; let cmp: (t, t) => int;}) => Comparable with type t = M.t;

comparableU

RE
let comparableU: (~cmp: [@bs] (('a, 'a) => int)) => (module BeltId.Comparable with type t = 'a);

comparable

RE
type ('key, 'id) comparable = (module BeltId.Comparable with type identity = 'id and type t = 'key)

Hashable

RE
module type Hashable = { type identity; type t; let hash: BeltId.hash(t, identity); let eq: BeltId.eq(t, identity); }

hashable

RE
type hashable('key, 'id) = (module BeltId.Hashable with type identity = 'id and type t = 'key);

is a module of functions, here it only includes hash, eq.

Unlike normal functions, when created, it comes with a unique identity (guaranteed by the type system).

It can be created using function Belt_Id.hashableU or Belt_Id.hashable.

The idea of a unique identity when created is that it makes sure two hash sets would type mismatch if they use different comparison function.

MakeHashableU

RE
module MakeHashableU: (M: {type t; let hash: [@bs] (t => int); let eq: [@bs] ((t, t) => bool);}) => Hashable with type t = M.t;

MakeHashable

RE
module MakeHashable: (M: {type t; let hash: t => int; let eq: (t, t) => bool;}) => Hashable with type t = M.t;

hashableU

RE
let hashableU: (~hash: [@bs] ('a => int), ~eq: [@bs] (('a, 'a) => bool)) => (module BeltId.Hashable with type t = 'a);

hashable

RE
let hashable: (~hash: 'a => int, ~eq: ('a, 'a) => bool) => (module BeltId.Hashable with type t = 'a);