创建函子时"illegal use of nesting marker"莫扎特错误



当用函子编译Oz代码时,我得到错误"非法使用嵌套标记";在其中";函子";已声明。这意味着什么?

functor
export
sum:Sum
divisao:Div
mult:Mult
sub:Sub
define
fun {Sum X Y} X + Y end
fun {Mult X Y} X * Y end
fun {Sub X Y} X - Y end
end

首先,您缺少div.的定义

functor
export
sum:Sum
divisao:Div
mult:Mult
sub:Sub
define
fun {Sum X Y} X + Y end
fun {Mult X Y} X * Y end
fun {Sub X Y} X - Y end
fun {Div X Y} X / Y end
end

functors是模块的定义,您可以将导入和导出定义为文件。您应该编译该文件并将其转换为一个模块。例如,调用文件test.oz并运行以下命令进行编译和运行。

ozc -c test.oz && ozengine test.ozf

如果通过向编译器提供缓冲区来运行Mozart,则不能直接使用functor,因为必须将其转换为模块。您必须首先声明它,然后使用Module.manager.应用它

declare F M ModMan
F = functor
export
sum:Sum
divisao:Div
mult:Mult
sub:Sub
define
fun {Sum X Y} X + Y end
fun {Mult X Y} X * Y end
fun {Sub X Y} X - Y end
fun {Div X Y} X / Y end
end
% To use the functions of the functor, apply it and create a module
ModMan = {New Module.manager init}
M = {ModMan apply(F $)}
% Then use the exported functions with module M
% Example:
{Show {M.sum 3 5}}
% >>> 8

最新更新