Uncurried mode - callback with two parameters

I’m trying to switch some code to uncurried mode and am having trouble using a callback that takes two parameters. I’ve searched the help and can’t find what I need. I’m trying to use the compare callback that takes two parameters. I can’t just pass it in where I want to use it. Instead I have to create a new function (a,b)=>compare(a,b). I’ve tried passing the callback as compare(...) and that didn’t work. Also notice the error message I get from the compiler isn’t helpful at all.

let sortBy: (t<'a>, ('a, 'a) => int) => t<'a>

// Compile error
let sortBy = (xx, compare) =>
  delay(() => {
    let xx = xx->toArray
    xx->Array.sortInPlaceWith(compare)->ignore
    xx->fromArray
  })

// Works
let sortBy = (xx, compare) =>
  delay(() => {
    let xx = xx->toArray
    xx->Array.sortInPlaceWith((a, b) => compare(a, b))->ignore
    xx->fromArray
  })

This is the error message

The implementation /Users/justinmagaram/Source/rescript-seq/src/Seq.res
  does not match the interface src/seq.cmi:
  Values do not match:
    let sortBy: (t<'a>, ('a, 'a) => int) => t<'a>
  is not included in
    let sortBy: (t<'a>, ('a, 'a) => int) => t<'a>

It probably means one of the two versions is curried and the other one is not, the error message got improved and should now be clear. What version of the compiler do you use?

Version 11.0.1. I’m not sure what happened but I’m now able to just pass the function in without creating a new lambda. Hmmm… So the problem seems to have gone away.

1 Like