【发布时间】:2022-12-10 16:55:25
【问题描述】:
let z = 4 in let y=5 in
try
y = z+x
with Failure msg -> msg = "Free identifier: x"
如果我们这样做,ocaml 怎么知道 try 是否失败?实际上,我正在尝试“使用失败消息尝试函数”,但我的函数必须返回 int 值。你如何通过返回 int 值让 ocaml 知道 try 失败了? 我的真实代码是这样的:
let func x y=x+y in
let y=5 in
try
func x y
with Failure msg -> msg = "Free identifier: x"
但是 func 必须返回 int 并且此代码不起作用
【问题讨论】:
标签: ocaml