Is it possible to use active patterns within discrimated union type declarations?
To be more precise, consider the following toy example:
type T =
| A of int
| B
let (|Negative|_|) t =
match t with
| A n when n < 0 -> Some ()
| _ -> None
let T_ToString = function
| Negative () -> "negative!"
| _ -> "foo!"
Now suppose I want to override ToString() in T. Inside T's type declaration I can't refer to T_ToString since T_ToString is not yet declared at that point. I can't move the active pattern and T_ToString before ToString() because T is not yet declared at that point. But this doesn't work either:
type T =
| A of int
| B
static member (|Negative|_|) t =
match t with
| A n when n < 0 -> Some ()
| _ -> None
override this.ToString () =
match this with
| Negative () -> "negative!"
| _ -> "foo!"