编译以下代码时出现错误
type shape =
| Circle int
| Square int
| Rectangle int int;
let myShape = Circle 10;
let area =
switch myShape {
| Circle r => float_of_int (r * r) *. 3.14
| Square w => float_of_int (w * w)
| Rectangle w h => float_of_int (w * h)
};
Js.log area;
致命错误:异常失败(“nth”)
忍者:构建停止:子命令失败。
当我将其更改Rectangle
为元组(int,int)时,它可以工作
type shape =
| Circle int
| Square int
| Rectangle (int, int);
let myShape = Circle 10;
let area =
switch myShape {
| Circle r => float_of_int (r * r) *. 3.14
| Square w => float_of_int (w * w)
| Rectangle (w, h) => float_of_int (w * h)
};
Js.log area;
数据构造函数不能有多个参数吗?
谢谢
问题已提交至buckelscript https://github.com/BuckleScript/bucklescript/issues/1822