Module Belt_Id

module Belt_Id: sig .. end
Belt.Id

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

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


type ('a, 'id) hash 
('a, 'id) hash

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

type ('a, 'id) eq 
('a, 'id) eq

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

type ('a, 'id) cmp 
('a,'id) cmp

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

module type Comparable = sig .. end
type ('key, 'id) comparable = (module Belt_Id.Comparable with type identity = 'id and type t = 'key) 
('key, 'id) cmparable 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 orBelt_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

module MakeComparableU: 
functor (M : sig
type t 
val cmp : (t -> t -> int [@bs])
end) -> Comparable with type t = M.t
module MakeComparable: 
functor (M : sig
type t 
val cmp : t -> t -> int
end) -> Comparable with type t = M.t
val comparableU : cmp:('a -> 'a -> int [@bs]) -> (module Belt_Id.Comparable with type t = 'a)
val comparable : cmp:('a -> 'a -> int) -> (module Belt_Id.Comparable with type t = 'a)
module type Hashable = sig .. end
type ('key, 'id) hashable = (module Belt_Id.Hashable with type identity = 'id and type t = 'key) 
('key, 'id) hashable 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

module MakeHashableU: 
functor (M : sig
type t 
val hash : (t -> int [@bs])
val eq : (t -> t -> bool [@bs])
end) -> Hashable with type t = M.t
module MakeHashable: 
functor (M : sig
type t 
val hash : t -> int
val eq : t -> t -> bool
end) -> Hashable with type t = M.t
val hashableU : hash:('a -> int [@bs]) ->
eq:('a -> 'a -> bool [@bs]) -> (module Belt_Id.Hashable with type t = 'a)
val hashable : hash:('a -> int) ->
eq:('a -> 'a -> bool) -> (module Belt_Id.Hashable with type t = 'a)