Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.74 KB | None | 0 0
  1. module type ORDERING = sig
  2.     type t
  3.     val (<) : t -> t -> bool
  4.     val (>) : t -> t -> bool
  5.     val (=) : t -> t -> bool
  6.     val compare : t -> t -> int
  7. end
  8.  
  9. module Int_ordering : ORDERING with type t = int = struct
  10.     type t = int
  11.     let (<) = Pervasives.(<)
  12.     let (>) = Pervasives.(>)
  13.     let (=) = Pervasives.(=)
  14.     let compare = Pervasives.compare
  15. end
  16.  
  17. module String_ordering : ORDERING with type t = string = struct
  18.     type t = string
  19.     let (<) x y = String.compare x y < 0
  20.     let (>) x y = String.compare x y > 0
  21.     let (=) x y = String.compare x y = 0
  22.     let compare = String.compare
  23. end
  24.  
  25. let sort_pair ordering (x, y) =
  26.     let module Ordering = (val ordering : ORDERING) in
  27.     if Ordering.(<) x y then (x, y) else
  28.     if Ordering.(>) x y then (y, x) else (x, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement