我正在尝试实现一个测试函数,以便比较并显示错误消息(如果它们不相等):
exception AssertionErrorException of string
fun assert(testName, actual, expect) : bool =
if actual = expect
then true
else raise (AssertionErrorException (testName ^ " failed. actual: " ^ actual
^ ", expect: " ^ expect ));
很遗憾,如果我使用非字符串参数调用它,它将无法正常工作:
assert("test1", SOME [], NONE);
它无法编译,错误信息为:
Error: operator and operand don't agree [tycon mismatch]
operator domain: string * string * string
operand: string * 'Z list option * 'Y option
in expression:
assert ("test1",SOME nil,NONE)
如何解决这个问题?