Per-function currying

The Belt.Set module documentation gives the following example:

module PairComparator =
  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
      }
  })

let mySet = Belt.Set.make(~id=module(PairComparator))
let mySet2 = Belt.Set.add(mySet, (1, 2))

This fails in ReScript 11.1.4 with the following error:

  Signature mismatch:
  ...
  Values do not match:
    let cmp: (('a, 'b), ('a, 'b)) => int (uncurried)
  is not included in
    let cmp: (t, t) => int (curried)

What’s the recommended way of solving this?

I found [this thread[(Type for curried function in uncurried mode?) which makes reference to the @@uncurried.swap decorator. Putting this above the definition of cmp or at the top of the file doesn’t do anything to the error.

“Manually” currying, i.e., changing ((a0, a1), (b0, b1)) => ... to (a0, a1) => (b0, b1) => ... gives a different type error:

  Signature mismatch:
  ...
  Values do not match:
    let cmp: ('a, 'b) => ('a, 'b) => int (uncurried)
  is not included in
    let cmp: (t, t) => int (curried)

Thanks in advance!

1 Like

I think you have to use the uncurried version of the Module Function. It’ll be sorted out in v12 since it’s uncurried only!

1 Like

Doh, should’ve looked there. Thank you!!

1 Like