F# records vs .net struct

后端 未结 4 2017
忘了有多久
忘了有多久 2021-02-05 18:52

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 P

4条回答
  •  死守一世寂寞
    2021-02-05 19:15

    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.

    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.BaseType = typeof //true
    

    Whereas

    type StructType = struct end
    typeof.BaseType = typeof //true
    typeof.BaseType = typeof //false
    

提交回复
热议问题