How do F # custom types map to CLR types?

I don’t know if the title of the question is clear, but I am wondering what types of user types are F #.

As in C #, there are value types and reference types. For F #, is there one type that governs the type system?

Are they all value types (since they are immutable by default)?

Or are there / are brand new types that do not look like a value / reference type?

Any information would be helpful.

+3
source share
4 answers

F # . .NET( #), , CLR.

Struct ( , # Struct), ,

[<Struct>]
type ValueType(a:int) =
   member x.A = a

type Enumeration = 
  | First = 1
  | Second = 2

F # F # CLR. F # ( ).

  • - , .
  • Tuple Tuple<...> ( .NET 4.0)

  • FSharpFunc<...>. F # currying and partial function, . , int -> int -> int FSharpFunc<int, FSharpFunc<int, int>>. Invoke, . F # , Invoke, , .

  • ( , ) . :

    type Shape = 
      | Rectangle of int * int * int * int
      | Circle of int * int * int 
    

    Shape Rectangle Circle (, Shape). , (, ).

, F # .

+12

ECMA 335 (CLI), & sect; 8.5.2 :

# ().

+3

.NET, #. F #, , , .NET- #.

, (, String), ( .NET) - / .

: .

+2

, F # - , , CLR, #, .

, , , , .

+1

Source: https://habr.com/ru/post/1765442/


All Articles