[sledge] Add Ord.( @? ) to lexicographically compose compare functions

Summary:
This allows easily defining lexicographic orders as a composition of
other orders. For example, the natural ordering on `int * string`
pairs can be written:
```
Ord.Infix.((Int.compare >|= fst) @? (String.compare >|= snd))
```

The `@?` name is chosen as a hybrid between `@@` which denotes
function composition and `<?>` which is the infix operator of
`Containers.Ord` for defining lexicographic orders.

Differential Revision: D29441161

fbshipit-source-id: ae9143cdc
master
Josh Berdine 3 years ago committed by Facebook GitHub Bot
parent 37aa0159ea
commit 7bb2e678e3

@ -43,7 +43,17 @@ module Poly : sig
val hash : 'a -> int val hash : 'a -> int
end end
module Ord = Containers.Ord module Ord : sig
include module type of Containers.Ord
val ( @? ) : 'a t -> 'a t -> 'a t
module Infix : sig
include module type of Containers.Ord.Infix
val ( @? ) : 'a t -> 'a t -> 'a t
end
end
(** Function combinators *) (** Function combinators *)

@ -55,7 +55,17 @@ module Poly = struct
let hash = Stdlib.Hashtbl.hash let hash = Stdlib.Hashtbl.hash
end end
module Ord = Containers.Ord module Ord = struct
include Containers.Ord
let ( @? ) c1 c2 x y = c1 x y <?> (c2, x, y)
module Infix = struct
include Infix
let ( @? ) = ( @? )
end
end
(** Function combinators *) (** Function combinators *)

Loading…
Cancel
Save