gpt4 book ai didi

f# - F# 中的 t <'a> and ' 和 t 有什么区别?

转载 作者:行者123 更新时间:2023-12-04 00:42:39 25 4
gpt4 key购买 nike

F#中的t<'a>'a t在含义上有什么区别吗?即使在声明之后它们可以互换使用吗?

最佳答案

没有区别,是的,即使在声明之后它们也可以互换使用。

但请注意 F# Component Design Guidelines建议(第 4.2 节):

Consider using the prefix syntax for generics (Foo<T>) in preference to postfix syntax (T Foo), with four notable exceptions (list, option, array, ref).

F# inherits both the postfix ML style of naming generic types, e.g. “int list” as well as the prefix .NET style, e.g. “list<int>”. You should prefer the .NET style, except for four specific types. For F# lists, use the postfix form: “int list” rather than “list<int>”. For options, use the postfix form: “int option” rather than “option<int>”. For arrays, use the syntactic name “int[]” rather than either “int array” or “array<int>”. For refs, use “int ref” rather than “ref<int>” or “Ref<int>”. For all other types, use the prefix form: “HashSet<int>”, “Dictionary<string,int>”, since this conforms to .NET standards



此外,如果您使用 ML 样式的通用参数列表表示法,您将收到编译器警告,例如 ('a,'b) tt<'a,'b> .

在此过程中,请注意 Section 3.1 中的以下建议同一指南:

Do use PascalCase for generic parameter names in public APIs, including for F#-facing libraries. In particular, use names like T, U, T1, T2 for arbitrary generic parameters, and when specific names make sense, then for F#-facing libraries use names like Key, Value, Arg (but not e.g. TKey).



(尽管我个人倾向于忽略面向 F# 的公共(public)库的这一建议)。

关于f# - F# 中的 t <'a> and ' 和 t 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10167359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com