Fable: Incorrect currying

Created on 14 Jul 2020  路  3Comments  路  Source: fable-compiler/Fable

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.

uncurrying

All 3 comments

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 馃憤

This took a while but should be finally fixed in 3.1.3 馃樃

That's great, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krauthaufen picture krauthaufen  路  3Comments

forki picture forki  路  3Comments

SirUppyPancakes picture SirUppyPancakes  路  3Comments

tomcl picture tomcl  路  4Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments