Array<(int, int)> to set


I have a type defined as:

type point = (int, int)

I also have a variable that hold an Array of those points.

I would like to create a Set from that array, but it seems I need to supply ~id value to Set.fromArray.

The example in the docs is:

let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp))

I tried to use that ~id and expected to get an error. The error I got is not exactly what I expected:

he module or file IntCmp can't be found.
  - If it's a third-party dependency:
    - Did you list it in bsconfig.json?
    - Did you run `bsb` instead of `bsb -make-world`
      (latter builds third-parties)?
  - Did you include the file's directory in bsconfig.json?

Is there more examples on how to create ~id for custom types?

How can I create an ~id for my case?

Thank you in advance.


Edit: regarding the error, see the note in

Note: This module’s examples will assume a predeclared module for integers called IntCmp . It is declared like this:…

1 Like

Thank you, @yawaramin.

I saw the note after I posted the question.

But what I have missed before is that there an exact my use case example! I copied it and now it’s working!

But what are Pervasives ?

I see those are mentioned, but I can’t find any documentation about them.

Pervasives is a standard library module inherited from OCaml:

ReScript ships with most of the important OCaml standard modules:

@yawaramin, thank you for the links.

Maybe they can be added to the ResScript docs?

Yeah, ideally they should be. I recommend creating a tracking issue on

1 Like

Note that Pervasives is open by default, so writing out is equivalent to just writing compare (unless you shadowed compare with your own function). You actually use Pervasives a lot without necessarily realizing it.

1 Like


Thank you, @johnj!