Fable generates curried function for ResizeArray.Sort

Created on 13 Apr 2018  路  2Comments  路  Source: fable-compiler/Fable

Description

This was reported by @ephja on Gitter. Fable generates a curried function if ResizeArray.Sort is used with a custom comparer function.

Repro code

let ns = ResizeArray<int> ()
ns.Sort compare

Expected and actual results

For the Sort method, Fable generates this:

ns.sort(function ($var1) {
  return function ($var2) {
    return (0, _Util.comparePrimitives)($var1, $var2);
  };
});

But this doesn't work at runtime (no runtime error, though). The call should rather look like this:

ns.sort(_Util.comparePrimitives);

You can work around this by using another function or with an extension method:

open Fable.Core.JsInterop
type System.Collections.Generic.List<'a> with
    member inline this.sort (f : 'a -> 'a -> int) : unit =
        !! (this?sort $ f)

ns.sort compare

_BTW, I love the fact that this works_ 馃槃

Related information

  • Fable version (dotnet fable --version): 1.3.14

Most helpful comment

Still reproduces with v2.

All 2 comments

Still reproduces with v2.

Thanks @inosik! You made me realize I've been doing it wrong all this time with to get the signature of delegate types coming from the BCL. There are a few more edge cases to solve but the general ones (including the one reported in this issue) will be fixes in the next release :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MangelMaxime picture MangelMaxime  路  3Comments

et1975 picture et1975  路  3Comments

krauthaufen picture krauthaufen  路  3Comments

SirUppyPancakes picture SirUppyPancakes  路  3Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments