gpt4 book ai didi

.net - F#记录与.net结构

转载 作者:行者123 更新时间:2023-12-04 01:35:37 25 4
gpt4 key购买 nike

f#记录与.net结构相同吗?我看到人们在谈论f#结构,他们使用的这个术语可以与F#记录互换吗?像FSharp runs my algorithm slower than Python中一样,谈论使用struct作为字典键但使用代码type Tup = {x: int; y: int}为什么在上面的链接中这比将元组作为字典键快?

最佳答案

不,实际上,F#中的记录类型只是一种引用类型,只是具有特殊的功能编程功能,例如属性上的模式匹配,更容易的不变性和更好的类型推断。

我认为Laurent的加速一定是出于其他原因,因为我们可以证明Tup不是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

关于.net - F#记录与.net结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858550/

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