This is a bit surprising behavior! I think it is happening because Failure
is another type that is defined in the F# core library. When you try calling the static method, the compiler (for some reason) picks only the F# library type, but does not union the static methods (which is what I would expect).
I think it might be a bug - so please report it on the F# CodePlex site.
As a workaround, I only came up with a fairly ugly idea, which is to define a private type alias such as FailureStatic
and then use the alias to call static members (the users of your library will not see it).
module Responses =
type private FailureStatic = Failure
and Failure =
| Problem of string
| Error of exn
| Timeout
static member toString x =
match x with
| Problem str -> sprintf "Problem %s" str
| Error e -> sprintf "Error %s" (e.ToString())
| Timeout -> "Timeout"
override x.ToString() = FailureStatic.toString x