【发布时间】:2010-12-22 06:43:23
【问题描述】:
我不确定是否允许非静态公共成员活动模式,但您可以在编译器不抱怨的情况下定义它们。如果它们被允许,匹配一个的语法是什么?编译器给了我 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 -> ()
【问题讨论】:
标签: f# member active-pattern