泛型与F#中的接口 [英] Generics with interfaces in F#
本文介绍了泛型与F#中的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class Something< T> T:IComparable
{
...
}
如何在F#中指定它?
解决方案
通用约束在F#中使用when
输入Foo<'a when a:> IComparable的> =
会员x.Bla = 0
In C# one can state that a generic parameter must implement a certain interface like so:
public class Something<T> where T : IComparable
{
...
}
How does one specify this in F#?
解决方案
Generic constraints use "when" in F#:
type Foo<'a when 'a :> IComparable> =
member x.Bla = 0
这篇关于泛型与F#中的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文