小编bob*_*ins的帖子

具有多种返回类型的函数:是否可能?

我有以下一些代码,我想返回一个布尔值或一个元组.(功能isvariabledont_care两者都返回布尔值,fyi)

let match_element (a, b) =
if a = b then true
else if (dont_care a) || (dont_care b) then true
else if (isvariable a) then (a, b)
else if (isvariable b) then (b, a)
else false;;
Run Code Online (Sandbox Code Playgroud)

目前,它引发了以下错误:

有什么方法可以解决这个问题吗?

This expression has type 'a * 'b
but an expression was expected of type bool
Run Code Online (Sandbox Code Playgroud)

(此函数基于Python程序的指令,我不确定它是否可以在OCaml中使用.)

ocaml strong-typing

2
推荐指数
1
解决办法
1437
查看次数

标签 统计

ocaml ×1

strong-typing ×1