F# records vs .net struct

后端 未结 4 2020
忘了有多久
忘了有多久 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:21

    As Stephen said, it is a reference type. Here is the compiled code(release mode) of type Tup = {x: int; y: int}:

    [Serializable, CompilationMapping(SourceConstructFlags.RecordType)]
    public sealed class Tup : IEquatable, IStructuralEquatable, IComparable, IComparable, IStructuralComparable
    {
        // Fields
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        internal int x@;
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        internal int y@;
    
        // Methods
        public Tup(int x, int y);
        ...
    
        // Properties
        [CompilationMapping(SourceConstructFlags.Field, 0)]
        public int x { get; }
        [CompilationMapping(SourceConstructFlags.Field, 1)]
        public int y { get; }
    }
    

提交回复
热议问题