为什么 Elm 0.19 中的“remainderBy 0 100”返回 NaN,而不是 Maybe Int?

Izu*_*iSy 5 javascript elm

在 JavaScript 中,0 % 100is 0,但在 Elm 中,相同操作的结果是 this。

> remainderBy 0 100
NaN : Int
Run Code Online (Sandbox Code Playgroud)

我只是认为remainderBy函数更好地返回Maybe Int如下所示。

> remainderBy 0 100
Nothing : Maybe Int

> remainderBy 6 3
Just 2 : Maybe Int
Run Code Online (Sandbox Code Playgroud)

Elm 有什么理由remainderBy退货NaN吗?

小智 4

第一个参数remainderBy是除数,与您的预期相反。所以remainderBy 0 100是一样的100 % 0

您除以 0,因此结果为 NaN。

  • 谢谢!但我也觉得在 Elm 世界中,NaN 并不受欢迎。为什么 Elm 不将其包装为 Maybe? (5认同)