I played with writing the type of the result and various functions and came across a type mismatch error that I cannot explain. Here is a minimal example:
type ('a, 'b) result = | Success of 'a | Failure of 'b list let apply fr xr = match fr, xr with | Success f, Success x -> Success (fx) | Failure _, Success _ -> fr | Success _, Failure _ -> xr | Failure a, Failure b -> Failure (List.concat [a; b])
Compiling this code causes the following error:
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 when unifying ''a' and ''b -> 'a'
If you change the apply function as follows, it compiles correctly:
let apply fr xr = match fr, xr with | Success f, Success x -> Success (fx) | Failure a, Success _ -> Failure a | Success _, Failure b -> Failure b | Failure a, Failure b -> Failure (List.concat [a; b])
Why using a matching value (here fr or xr) doesn't work, but building a new Failure value does?
source share