Fable: Different behaviour for decimals in REPL and compiler

Created on 29 Jul 2017  路  6Comments  路  Source: fable-compiler/Fable

@eiriktsarpalis has reported in Twitter that let incr x = x + 1M in the REPL is compiled as:

export function incr(x) {
  return x + 0;
}

While the compiler actually transforms it to:

function incr(x) {
  return applyOperator(x, 1, "op_Addition");
}

@ncave I think we already talked about the differences when dealing with decimal in the REPL, do you know why 1M gets converted to 0 here?

BTW, maybe it's time to have a proper type for decimal. We could do something similar as with Long and use a external library like decimal.js to support decimals with arbitrary precision. However, I haven't found anything with a five-argument constructor to translate MakeDecimal. Any ideas?

Most helpful comment

@alfonsogarciacaro Fixed in this, can be closed after it's merged (see also this).

All 6 comments

@alfonsogarciacaro The REPL just needs to be rebuilt (build, then build repl) and redeployed, as it's running an old version of the Fable compiler. Then the decimal behavior will be the same. There are pros and cons to decimal as JS object instead of float, performance being one, but yeah, that constructor will have to be added as it's not there. Another option is perhaps using something like the BigRational from the F# Powerpack.

Unfortunately this seems to still be happening after updating the REPL :/

@alfonsogarciacaro It's something different, now I'm getting this:
FSharp.Compiler.Service cannot yet return this kind of constant at stdin.fsx (1,17--1,19) IsSynthetic=false (stdin.fsx)

Let's call it a step forward :wink:

@alfonsogarciacaro Fixed in this, can be closed after it's merged (see also this).

This is fantastic, thank you! Pinging @vasily-kirichenko who also reported this in Twitter.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

theprash picture theprash  路  3Comments

SirUppyPancakes picture SirUppyPancakes  路  3Comments

et1975 picture et1975  路  3Comments

ncave picture ncave  路  3Comments