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(sortFunction) =
member this.SortFunction with get() = sortFunction
member this.Execute(list) = sortFunction list
let strategy() =
let s = Strategy(quicksort)
s.Execute([1..6])
strategy()
|
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 : sortFunction:(int list -> unit) -> Strategy
member Execute : list:int list -> unit
member SortFunction : (int list -> unit)
Full name: Script.Strategy
--------------------
new : sortFunction:(int list -> unit) -> Strategy
val sortFunction : (int list -> unit)
val this : Strategy
member Strategy.SortFunction : (int list -> unit)
Full name: Script.Strategy.SortFunction
member Strategy.Execute : list:int list -> unit
Full name: Script.Strategy.Execute
Multiple items
val list : int list
--------------------
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
val strategy : unit -> unit
Full name: Script.strategy
val s : Strategy
member Strategy.Execute : list:int list -> unit
More information