Broken example code in Belt api

Hi I’m in the process of learning ReScript and I noticed some of the code examples in the Belt documentation are out of date.

On this page

this code example

module Comparable1 =
  Belt.Id.MakeComparable(
    {
      type t = (int, int)
      let cmp = ((a0, a1), (b0, b1)) =>
        switch Pervasives.compare(a0, b0) {
        | 0 => Pervasives.compare(a1, b1)
        | c => c
        }
    }
  )

results in this error

[E] Line 3, column 4:

Signature mismatch:

Values do not match:
let cmp: (('a, 'b), ('a, 'b)) => int (uncurried)
is not included in
let cmp: (t, t) => int (curried)
playground.res: Expected declaration
playground.res:5:11-13: Actual declaration

It’s not clear to me immediately what the problem is.
Thanks for any help, I’m enjoying learning and using ReScript so far.

Oh yeah that’s a bit hard to grasp right now, this will be solved in ReScript v12, but for now you have this issue with the libraries shipped with the compiler (like Belt), it doesn’t automatically follow the (un)curried setting of your project, so you have to do it manually, so if you have set up your project in uncurried mode you have to use the U version of Belt functions, for example in this case (playground link), do this:

module Comparable1 = Belt.Id.MakeComparableU({
  type t = (int, int)
  let cmp = ((a0, a1), (b0, b1)) =>
    switch Pervasives.compare(a0, b0) {
    | 0 => Pervasives.compare(a1, b1)
    | c => c
    }
})
3 Likes

Okay, thanks!. That fixed my issue and makes sense.