How to bind to a curried JS function

I’m learning Reason and trying to incorporate Fluture into my project. I found bs-fluture. bs-fluture binds version 10.2.0 whereas the current version is 13.0.1.

Since version 10, the type signature of the “fork” function has changed to a curried version:
fork :: (a -> Any) -> (b -> Any) -> Future a b -> Cancel

The bs-fluture binding is:

[@bs.module “fluture”]
external fork: ('e => unit, 'v => unit, t('e, 'v)) => cancelJs;

Using this generates the following type error:

Uncaught TypeError: fork() expects to be called with a single argument per invocation

I created a gist with a simple example that demonstrates the problem.

How do I bind to a JS function that is curried? I read the Curry & Uncurry section of the Interop manual but I didn’t see an answer there.

Thanks!

Hey! I wrote this library, I had completely forgotten about it until I read this post and thought ‘I recognise this package name, wonder who made it?’ :sweat_smile:

I’m very happy to upgrade it to match the latest version. I’m not at a computer right now, any chance you could file an issue on the repo with this info about what’s not working so I can track it?

The difficulty of binding to a function that’s curried in JS is that ReScript sees these two signatures as identical:

type curriedFunc = int => int => int
type uncurriedFunc = (int, int) => int

But there are ways around this. I believe the most straightforward method is to put the returned function in its own type:

type returnedFunc = int => int
type curriedFunc = int => returnedFunc

Now when ReScript compiles curriedFunc, it won’t automatically uncurry it.

4 Likes

Thank you! I updated my gist with a working version.

Hi, I’ve just released v1.0.0 of bs-fluture which supports the new curried Fluture API. Let me know if you discover any issues, I added a large amount of tests so I’m pretty confident it works as expected now with the latest version of Fluture.

Some high level suggestions to bindings to curried functions. curry is a subset of uncurry, if you are uncertain how curry works with bindings, always go with uncurry

1 Like