是否可以使用具体的类型参数对泛型类型进行类型扩展?这些语法使我失败了:
语法1:
type Foo<Bar> with
member this.BarStuff = // access `Bar´ specifics
语法2:
type Foo<'T when 'T :> Bar> with
member this.BarStuff = // access `Bar´ specifics
答案 0 :(得分:3)
是的,可以,但是您应该使用C#样式语法:
open System.Runtime.CompilerServices
type Bar = Bar
type Foo<'t> = Foo of 't
[<Extension;Sealed>]
type Extensions =
[<Extension>]
static member BarStuff (this: Foo<Bar>) = ()
let x = (Foo Bar).BarStuff