问题描述
为f#记录是相同的。净结构?我看到人们谈论F#结构,都用这个词互换使用F#记录?就像FSharp运行速度比Python的我的算法慢,讨论一下如何利用结构作为字典键,但与code 键入托普= {X:INT; Y:INT}
为什么这个速度比一个元组在上面的链接字典键?
is f# records is the same as .net struct? I saw people talk about f# struct,are they use this term interchangable with F# records? Like in FSharp runs my algorithm slower than Python!, talking about using struct as dictionary key but with code type Tup = {x: int; y: int}
Why is this faster than a tuple as a dictionary key in the link above?
推荐答案
没有,其实在F#记录类型为引用类型仅仅是具有特殊功能的编程功能,如对性能的模式匹配,更容易不变性,更好的类型推断
No, in fact, a record type in F# is a reference type just with special functional programming features like pattern matching on properties, easier immutability, and better type inference.
我觉得Laurent的增速一定是因为其他原因,因为我们能证明托普
不是值类型:
I think Laurent's speedup must have been for other reasons, because we can prove that Tup
is not a ValueType:
type Tup = {x: int; y: int}
typeof<Tup>.BaseType = typeof<System.Object> //true
而
type StructType = struct end
typeof<StructType>.BaseType = typeof<System.ValueType> //true
typeof<StructType>.BaseType = typeof<System.Object> //false
这篇关于F#记录VS .NET结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!