Fable: Error when composing 2 functions

Created on 5 Mar 2018  路  4Comments  路  Source: fable-compiler/Fable

Description

There is a runtime error when composing 2 functions. The same code works fine when composition operator is avoided (e.g. let foo = squarePromise 4 |> createPromise)

Repro code

open Fable.Core

let squarePromise a resolve reject =
    resolve (a*a)

[<Emit("new Promise($0)")>]
let createPromise (f: ('a -> unit) -> (System.Exception -> unit) -> unit): Fable.Import.JS.Promise<'a> = jsNative

let foo =
    (squarePromise >> createPromise) 4

Expected and actual results

Expected: foo should contain a promise that is resolved to 16
Actual: Uncaught TypeError: Promise resolver undefined is not a function

Related information

  • Fable version (dotnet fable --version): 1.3.10
  • Operating system: Ubuntu 16.0.4
  • The bug is also reproducible in the REPL: (http://fable.io/repl/#?code=open%20Fable.Core%0A%0Alet%20squarePromise%20a%20resolve%20reject%20%3D%0A%20%20%20%20resolve%20(a*a)%0A%0A%5B%3CEmit(%22new%20Promise(%240)%22)%3E%5D%0Alet%20createPromise%20(f%3A%20('a%20-%3E%20unit)%20-%3E%20(System.Exception%20-%3E%20unit)%20-%3E%20unit)%3A%20Fable.Import.JS.Promise%3C'a%3E%20%3D%20jsNative%0A%0Alet%20foo%20%3D%0A%20%20%20%20(squarePromise%20%3E%3E%20createPromise)%204%0A&html=%3Chtml%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E)

Most helpful comment

Great, thanks for your understanding! For me personally, the best donation is you keep using Fable, post about it and help make it better everyday, so companies trust the tool I (and others) can get professional projects using Fable :)

All 4 comments

Thanks for the report @durkiewicz and sorry for replying late. This seems due to the current way in Fable 1 to "uncurry" lambdas which relies mainly in runtime checks and it fails in some cases. I've tested with Fable 2 (dev2.0 branch) and the error is not happening. I am trying to release the next version soon, would it be possible for you to use the work around (|> operator) until the next version is ready? If necessary, I can also try to fix it for the current version.

Hi Alfonso, thanks for replying. It's nice to hear that the bug is going to be fixed in Fable 2. I'm fine with using the workaround - I just need to be careful.

BTW, the fable.io page should have a donation button!

Great, thanks for your understanding! For me personally, the best donation is you keep using Fable, post about it and help make it better everyday, so companies trust the tool I (and others) can get professional projects using Fable :)

Fixed in Fable 2 so we can close this :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MangelMaxime picture MangelMaxime  路  3Comments

theprash picture theprash  路  3Comments

jwosty picture jwosty  路  3Comments

ncave picture ncave  路  3Comments

forki picture forki  路  3Comments