Mahesh
Mahesh

Reputation: 169

Is option type in F# reference type?

Is uint64 option type reference type or value type? I am having some performance issues related to this. please clarify.

Upvotes: 1

Views: 215

Answers (2)

John Palmer
John Palmer

Reputation: 25516

As None is implicitly represented as null, Option is a reference type.

The F# spec gives the following definition which requires option to be a reference type:

[<DefaultAugmentation(false)>]
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]    
type 'T option =
    | None 
    | Some of 'T
    static member None : 'T option
    static member Some : 'T -> 'T option
    [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
    member Value : 'T
    member IsSome : bool
    member IsNone : bool    

Upvotes: 4

weismat
weismat

Reputation: 7411

type Option<'T> = 
        | None :       'T option
        | Some : Value:'T -> 'T option 

from FSharp Source Code shows that is a reference type.

Upvotes: 0

Related Questions