I now have a list: list<Result<RuleType, exn>>
(RuleType
is a normal DU), and I am trying to convert it to Result<RuleType list, exn>
by using the traverse
method. Everything seems fine (no editor warning) until I attempted to compile it.
It gives this error error FS0041: No overloads match for method '<*>'
and following it was a bunch of undecipherable mess (full log is here: sequence Error - Pastebin.com)
I have no idea about what have happened.
A lot of times using sequence
or traverse
with Result
will blow up because it can’t at all infer that the error type remains the same. The solution is to annotate every piece (the output of the traverse
call, as well as the output of the function being passed to traverse
). You might alternatively have some luck specializing the traverse function like
let inline traverseResult (f : 'a -> Result<'b, 'e>) (xs : 'a list) : Result<'b list, 'e> = traverse f xs
(of course you’d probably have to specialize the traversable as well, but maybe if you just did that as a local definition or something)
2 Likes