本文介绍了在F#方法签名中,泛型指示符'和符号^之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道表示泛型参数的记号,如下所示:

  Seq.append:seq< T> - > SEQ< T> - > SEQ< T> 

但插入符号意味着什么,如下所示:

  Seq.average:seq< ^ T> - > ^ T 


解决方案

详细的签名是:


$ b

不同于 Seq.append ,需要对元素类型进行更多的约束。特别是:

  _ DivideByInt(s1 + s2 + ... + sn)n其中n< 0 
Seq.average {s1; S2; ...; sn} = /
\_ ^ T.Zero其中n = 0

可以看到(+) DivideByInt 为了使 Seq.average< ^ T> 有意义。

有关泛型的有用信息可以参见。


I understand the tick to signify a generic parameter, as in:

Seq.append : seq<'T> -> seq<'T> -> seq<'T>

but what does the caret signify, as in:

Seq.average : seq<^T> -> ^T
解决方案

The detailed signature is:

Unlike Seq.append, Seq.average needs some more constraints on type of elements. Particularly:

                                _ DivideByInt (s1 + s2 + ... + sn) n where n <> 0
Seq.average {s1; s2;...; sn} = /
                               \_ ^T.Zero where n = 0

As you can see, both (+), DivideByInt and Zero are required in order that Seq.average<^T> makes sense.

Useful information about generics could be found here.

这篇关于在F#方法签名中,泛型指示符'和符号^之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:30