带有多个参数的Reasonml类型,错误异常失败(“n”)
编译以下代码时出错带有多个参数的Reasonml类型,错误异常失败(“n”),reason,bucklescript,Reason,Bucklescript,编译以下代码时出错 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
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;
致命错误:异常失败(“n”)忍者:构建已停止:子命令 失败了 当我将
矩形
更改为tuple(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这两个变体都是完全有效的原因码。您可以使用具有多个参数的构造函数,并且您做得很好。显然,问题出在
Js.log
函数中,这是一种神奇的函数,使用n元构造函数,神奇就失败了
因此,我的建议是(i)在bucklescript bug tracker中提交一个问题,(ii)不要使用magic
Js.log
函数,而是派生或编写自己的打印机函数并使用它 这个异常看起来像是一个编译器错误。使用一种更新的语言的诸多痛苦之一——一定要向Reason提交一份错误报告,以便开发人员了解它。同时,也可能有用吗?不确定这个插件是否能完全实现OP想要的功能,甚至不一定能合理工作,但值得一看