Is there a good reference that tabulates which F# types are value types and which are reference types? Alternatively, is there a good way to query a type to determine which it is? Yes, I know that things that are classes are reference types and things that are structs are value types. At the same time, this distinction isn't always intuitive to me with F# types. For example, tuple types are reference types. Evidently, so are record types.
Asked
Active
Viewed 164 times
1 Answers
4
You can always check whether something is a value type using F# Interactive:
typeof<int * int>.IsValueType
As you mentioned, tuples are reference types and so this returns false
.
I agree that the difference is not always clear. In general, most types that you work with in F# are reference types (and all F# types that you define with the exception of struct types).
- Primitive types (numerical and booleans) are value types
- But
string
is a reference type - There are a couple of struct types defined in .NET like
DateTime
andTimeSpan
and alsoKeyValuePair
(this is sometimes confusing as this is quite similar to tuple). - F# tuples, records, discriminated unions, lists, arrays are all reference types
- F# object types are also reference types unless they are marked as
Struct
.

Tomas Petricek
- 240,744
- 19
- 378
- 553