我正在学习 F# 并想实现 ThreadStatic 单例。我正在使用在类似问题中找到的内容:F# How to implement Singleton Pattern (syntax)
使用以下代码编译器抱怨The type 'MySingleton' does not have 'null' as a proper value
.
type MySingleton =
private new () = {}
[<ThreadStatic>] [<DefaultValue>] static val mutable private instance:MySingleton
static member Instance =
match MySingleton.instance with
| null -> MySingleton.instance <- new MySingleton()
| _ -> ()
MySingleton.instance
在这种情况下如何初始化实例?