我正在玩写结果类型和各种功能,并遇到了我无法解释的类型不匹配错误.这是一个最小的例子:
type ('a, 'b) result =
| Success of 'a
| Failure of 'b list
let apply fr xr =
match fr, xr with
| Success f, Success x -> Success (f x)
| Failure _, Success _ -> fr
| Success _, Failure _ -> xr
| Failure a, Failure b -> Failure (List.concat [a; b])
Run Code Online (Sandbox Code Playgroud)
编译此代码会产生以下错误:
init.fsx(8,31): error FS0001: Type mismatch. Expecting a
('a,'b) result
but given a
(('c -> 'a),'d) result
The resulting type would be infinite …Run Code Online (Sandbox Code Playgroud) f# ×1