83 people like it.
    Like the snippet!
  
  Strategy pattern
  Strategy pattern in F#
   1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
  | 
let quicksort l = 
    printfn "quick sort"
let shellsort l = 
    printfn "shell short"
let bubblesort l = 
    printfn "bubble sort"
type Strategy() = 
    let mutable sortFunction = fun _ -> ()
    member this.SetStrategy(f) = sortFunction <- f
    member this.Execute(n) = sortFunction(n)
let stragegy() = 
    let s = Strategy()
    s.SetStrategy(quicksort)
    s.Execute([1..6])
  | 
val quicksort : l:'a -> unit
Full name: Script.quicksort
val l : 'a
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val shellsort : l:'a -> unit
Full name: Script.shellsort
val bubblesort : l:'a -> unit
Full name: Script.bubblesort
Multiple items
type Strategy =
  new : unit -> Strategy
  member Execute : n:int list -> unit
  member SetStrategy : f:(int list -> unit) -> unit
Full name: Script.Strategy
--------------------
new : unit -> Strategy
val mutable sortFunction : (int list -> unit)
val this : Strategy
member Strategy.SetStrategy : f:(int list -> unit) -> unit
Full name: Script.Strategy.SetStrategy
val f : (int list -> unit)
member Strategy.Execute : n:int list -> unit
Full name: Script.Strategy.Execute
val n : int list
val stragegy : unit -> unit
Full name: Script.stragegy
val s : Strategy
member Strategy.SetStrategy : f:(int list -> unit) -> unit
member Strategy.Execute : n:int list -> unit
  
  
  More information