Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect currying #2116

Closed
stkb opened this issue Jul 14, 2020 · 3 comments · Fixed by #2377
Closed

Incorrect currying #2116

stkb opened this issue Jul 14, 2020 · 3 comments · Fixed by #2377

Comments

@stkb
Copy link

stkb commented Jul 14, 2020

I've had a bit of trouble with bugs in currying/uncurrying lately, but have managed to find a minimal example for one:

Repl link

let optionFn = Some (fun x y -> x + y)

let list = List.choose id [optionFn]

printfn "List length: %d" (List.length list)
printfn "Answer %d" (List.head list 3 4) // Expect 7 but get 0

Javascript:

import { curry } from "fable-library/Util.js";
import { List } from "fable-library/Types.js";
import { head, length, choose } from "fable-library/List.js";
import { toConsole, printf } from "fable-library/String.js";
export function optionFn(x) {
  return function (y) {
    return x + y;
  };
}
export const list = choose(function (x$$1) {
  return curry(2, x$$1);
}, new List(optionFn, new List()));

(function () {
  const arg10 = length(list) | 0;
  const clo1 = toConsole(printf("List length: %d"));
  clo1(arg10);
})();

(function () {
  const arg10$$1 = head(list)(3)(4) | 0;
  const clo1$$1 = toConsole(printf("Answer %d"));
  clo1$$1(arg10$$1);
})();

In the javascript, curry(2, x$$1) is called on the input function, but it's already curried, and the end result is invalid.

I'm not sure what the essential elements are but that the function is wrapped in an Option seems to be one.

@alfonsogarciacaro
Copy link
Member

Thanks a lot for the code to reproduce @stkb! Yes, the fact that Fable erases option creates some trouble with currying/uncurrying but hopefully we can fix it thanks to your sample 👍

@alfonsogarciacaro
Copy link
Member

This took a while but should be finally fixed in 3.1.3 😸

@stkb
Copy link
Author

stkb commented Feb 15, 2021

That's great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants