reason-ml这是一个类型推断问题?

net*_*nel 0 types compiler-errors reason

我正在尝试理性并遇到一个我不明白的错误

这是我的代码:

let mult = (x:float, y:float):float => x * y;
Run Code Online (Sandbox Code Playgroud)

当我使用BuckleScript编译它时,我收到以下错误:

  We've found a bug for you!
  D:\1\bbl\orga\src\demo.re 1:40

  1 Ôöé let mult = (a:float, b:float):float => a * b;

  This has type:
    float
  But somewhere wanted:
    int

You can convert a float to a int with int_of_float.If this is a literal, you want a number without a trailing dot (e.g. 20).
Run Code Online (Sandbox Code Playgroud)

我不明白为什么编译器会需要打开一个floatint这里

Nei*_*ner 6

我的建议是删除类型,让推理处理它,它真的很好.

但是,如果您想保留特定类型,则需要更改运营商.你所拥有的是两个整数相乘.如果要将两个浮点数相乘,则将其更改为:

*

请注意,接线员就*.*,表示浮点运算.

请在此处查看更多文档:https://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#1_Floatingpointarithmetic

  • 另外,https://reasonml.github.io/docs/en/integer-and-float.html#design-decisions。 (2认同)