相关疑难解决方法(0)

F#活动模式作为非静态成员

我不确定是否允许非静态公共成员活动模式,但您可以在没有编译器抱怨的情况下定义它们.如果允许它们与一个匹配的语法是什么?编译器在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 …
Run Code Online (Sandbox Code Playgroud)

f# member active-pattern

4
推荐指数
1
解决办法
463
查看次数

标签 统计

active-pattern ×1

f# ×1

member ×1