Inheritance 参数多态性与子类型多态性F#

Inheritance 参数多态性与子类型多态性F#,inheritance,f#,functional-programming,parametric-polymorphism,subtyping,Inheritance,F#,Functional Programming,Parametric Polymorphism,Subtyping,这两个F#类型签名之间有什么区别(如果有) UseTheStream<'a when 'a :> Stream> : 'a -> unit 在这种情况下,它们的意思是一样的吗 msdn对(:>)类型约束做了如下说明 type-parameter :> type -- The provided type must be equal to or derived from the type specified, or, if the type is an

这两个F#类型签名之间有什么区别(如果有)

UseTheStream<'a when 'a :> Stream> : 'a -> unit
在这种情况下,它们的意思是一样的吗

msdn对(:>)类型约束做了如下说明

type-parameter :> type --   The provided type must be equal to or derived from the type      specified, or, if the type is an interface, the provided type must implement the interface.

这表明两个签名所说的是同一件事。那么,在功能上,它们有什么不同呢?

它们是不同的。最重要的是,第一个函数是泛型的。在您的示例中,这可能无关紧要,但如果type参数影响函数的返回类型,则会:

让我们使用流(流:#流)=流
让我们使用streamstrit(stream:stream)=stream
让s1=新内存流()|>使用流
让s2=新内存流()|>使用streamstrict
s1
MemoryStream
<代码>s2是


注意:
#T
'U when'U:>T

的简写,谢谢您为我澄清这一点。
type-parameter :> type --   The provided type must be equal to or derived from the type      specified, or, if the type is an interface, the provided type must implement the interface.