Strategy pattern

Strategy pattern in F#

Copy Source
Copy Link
Tools:
 1: let quicksort l = 
 2:     printfn "quick sort"
 3: let shellsort l = 
 4:     printfn "shell short"
 5: let bubblesort l = 
 6:     printfn "bubble sort"
 7: type Strategy(sortFunction) = 
 8:     member this.SortFunction with get() = sortFunction    
 9:     member this.Execute(list) = sortFunction list
10: 
11: let strategy() = 
12:     let s = Strategy(quicksort)    
13:     s.Execute([1..6])
14: 
15: strategy()
val quicksort : 'a -> unit

Full name: Snippet.quicksort
val l : 'a
val printfn : Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val shellsort : 'a -> unit

Full name: Snippet.shellsort
val bubblesort : 'a -> unit

Full name: Snippet.bubblesort
type Strategy =
  class
    new : sortFunction:(int list -> unit) -> Strategy
    member Execute : list:int list -> unit
    member SortFunction : (int list -> unit)
  end

Full name: Snippet.Strategy
val sortFunction : (int list -> unit)
val this : Strategy
property Strategy.SortFunction: int list -> unit
member Strategy.Execute : list:int list -> unit

Full name: Snippet.Strategy.Execute
Multiple items
val list : int list

  type: int list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<int>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<int>
  implements: System.Collections.IEnumerable


--------------------

type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>

  type: 'T list
  implements: System.Collections.IStructuralEquatable
  implements: System.IComparable<List<'T>>
  implements: System.IComparable
  implements: System.Collections.IStructuralComparable
  implements: System.Collections.Generic.IEnumerable<'T>
  implements: System.Collections.IEnumerable
val strategy : unit -> unit

Full name: Snippet.strategy
val s : Strategy
member Strategy.Execute : list:int list -> unit

More information

Link: http://fssnip.net/7k
Posted: 2 years ago
Author: Tao Liu (website)
Tags: Design Patterns