我不确定是否允许非静态公共成员活动模式,但您可以在编译器不抱怨的情况下定义它们。如果他们被允许,匹配一个的语法是什么?编译器给了我 FooBar2.doSomething 中 Foo 的类型不匹配。期待一个'a -> Choice<'b,'c>
给定的'a -> 'd -> Choice<unit,unit>
// No error in this class, static works great
type FooBar() =
static member (|Foo|Bar|) (x, y) =
match x = y with
| true -> Foo
| false -> Bar
member x.doSomething y =
match x, y with
| Foo -> ()
| Bar -> ()
type FooBar2() =
member x.(|Foo|Bar|) y =
match x = y with
| true -> Foo
| false -> Bar
// compiler error on "Foo"
member x.doSomething y =
match y with
| Foo -> ()
| Bar -> ()