39 people like it.

Singleton Pattern

singleton pattern in F#

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
type A private () =
    static let instance = A()
    static member Instance = instance
    member this.Action() = printfn "action"

let DesignPatter1() = 
    let a = A.Instance;
    a.Action()
type A =
  private new : unit -> A
  member Action : unit -> unit
  static member Instance : A

Full name: Script.A
val instance : A
private new : unit -> A
static member A.Instance : A

Full name: Script.A.Instance
val this : A
member A.Action : unit -> unit

Full name: Script.A.Action
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val DesignPatter1 : unit -> unit

Full name: Script.DesignPatter1
val a : A
property A.Instance: A
member A.Action : unit -> unit
Raw view New version

More information

Link:http://fssnip.net/7p
Posted:6 years ago
Author:Tao Liu
Tags: design patterns