我有以下示例,即使这些类型相互匹配,它们也不起作用
- isSome;
val it = fn : 'a option -> bool
- SOME;
val it = fn : 'a -> 'a option
- val my_converter = (fn x => if x = 5 then SOME x else NONE);
val my_converter = fn : int -> int option
SOME和my_converter都会返回一个选项,但是当我执行以下操作时
- fn x => isSome o SOME x;
stdIn:19.9-19.24 Error: operator and operand don't agree [tycon mismatch]
operator domain: ('Z option -> bool) * ('Y -> 'Z option)
operand: ('Z option -> bool) * 'X option
in expression:
isSome o SOME x
我收到类型错误原因?
答案 0 :(得分:1)
错误消息告诉您o
想要一个函数操作数,但实际得到的是option
。这是因为isSome o SOME x
解析为isSome o (SOME x)
,这没有任何意义。
您可以通过编写
来解决此问题(isSome o SOME) x
代替。