f#记录是否与.net结构相同?我看到人们谈论f#struct,他们是否使用这个术语与F#记录可互换?就像在FSharp中运行我的算法比Python慢,谈论使用struct作为字典键但是使用代码type Tup = {x: int; y: int}为什么这比上面的链接中的字典键更快?
Ste*_*sen 16
不,实际上,F#中的记录类型是一种引用类型,只是具有特殊的函数编程功能,如属性上的模式匹配,更容易的不变性和更好的类型推断.
我认为Laurent的加速一定是出于其他原因,因为我们可以证明这Tup不是ValueType:
type Tup = {x: int; y: int}
typeof<Tup>.BaseType = typeof<System.Object> //true
Run Code Online (Sandbox Code Playgroud)
而
type StructType = struct end
typeof<StructType>.BaseType = typeof<System.ValueType> //true
typeof<StructType>.BaseType = typeof<System.Object> //false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3821 次 |
| 最近记录: |