Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1774

Uncurried mode - callback with two parameters

$
0
0

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>

Viewing all articles
Browse latest Browse all 1774

Trending Articles