Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • X
  • BlueSky
  • GitHub
  • Forum
Belt Stdlib
Overview
  • Introduction
Basics
  • Array
  • List
  • Float
  • Int
  • Range
  • Id
    • cmp
    • comparable
    • comparable
    • Comparable
    • comparableU
    • eq
    • hash
    • hashable
    • hashable
    • Hashable
    • hashableU
    • MakeComparable
    • MakeComparableU
    • MakeHashable
    • MakeHashableU
  • Option
  • Result
Set
  • HashSet
  • HashSetInt
  • HashSetString
  • Set
  • SetDict
  • SetInt
  • SetString
Map
  • HashMap
  • HashMapInt
  • HashMapString
  • Map
  • MapDict
  • MapInt
  • MapString
Mutable Collections
  • MutableMap
  • MutableMapInt
  • MutableMapString
  • MutableQueue
  • MutableSet
  • MutableSetInt
  • MutableSetString
  • MutableStack
Sort Collections
  • SortArray
  • SortArrayInt
  • SortArrayString
Utilities
  • Debug
API / Belt / Id

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

RES
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

RES
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

RES
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

RES
module type Comparable = { type identity type t let cmp: Belt.Id.cmp<t, identity> }

comparable

RES
type comparable<'key,'id> = module(Belt.Id.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

RES
module MakeComparableU: (M: { type t let cmp: (. t, t) => int }) => Comparable with type t = M.t

MakeComparable

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

comparableU

RES
let comparableU: (~cmp: (. 'a, 'a) => int) => module(Belt.Id.Comparable with type t = 'a)

comparable

RES
type comparable<'key, 'id> = module(Belt.Id.Comparable with type identity = 'id and type t = 'key)

Hashable

RES
module type Hashable = { type identity type t let hash: Belt.Id.hash<t, identity> let eq: Belt.Id.eq<t, identity> }

hashable

RES
type hashable<'key, 'id> = module(Belt.Id.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

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

MakeHashable

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

hashableU

RES
let hashableU: (~hash: (. 'a) => int, ~eq: (. 'a, 'a) => bool) => module(Belt.Id.Hashable with type t = 'a)

hashable

RES
let hashable: (~hash: 'a => int, ~eq: ('a, 'a) => bool) => module(Belt.Id.Hashable with type t = 'a)

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on