如何统一实现接口和相同类型作为参数的类型?

时间:2017-11-26 13:42:39

标签: f#

鉴于以下类型

type IDocPartX<'delta, 'pures> = 
    abstract member ToDelta: 'pures -> 'delta
    abstract member ToPure: 'delta -> 'pures
    abstract member Validate: 'pures -> Option<'pures>

type InitX<'a>(v:'a) =
    member this.Value = v

type Foo<'a> = {value: 'a} with
    interface IDocPartX<Foo<int>, Foo<string>> with 
        member this.ToDelta x = Unchecked.defaultof<_>
        member this.ToPure x = Unchecked.defaultof<_>
        member this.Validate x = Unchecked.defaultof<_> 

这个功能

let inline ValidateInitX(x:InitX<IDocPartX<'d,'p>>) = 
    let r = x.Value
    let d = r :?> 'd
    let o = 
        d
        |> r.ToPure
        |> r.Validate
    match o with
    | Some v -> r.ToDelta v |> Init |> Some
    | _ -> None

和这个值

let a = InitX {value = 1}
let b = ValidateInitX a

为什么值a无法识别为InitX<IDocPartX<'a, 'b>>

0 个答案:

没有答案