Created
October 11, 2019 11:59
-
-
Save keleshev/e5bc4e60eb3dd46b059c0850b03de791 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec compare_lengths l1 l2 = | |
match l1, l2 with | |
| [], [] -> 0 | |
| [], _ -> -1 | |
| _, [] -> 1 | |
| _ :: l1, _ :: l2 -> compare_lengths l1 l2 | |
let rec compare_length_with l n = | |
match l with | |
| [] -> | |
if n = 0 then 0 else | |
if n > 0 then -1 else 1 | |
| _ :: l -> | |
if n <= 0 then 1 else | |
compare_length_with l (n-1) | |
module List = struct | |
type 'a t = 'a list | |
module Length = struct | |
type t = | |
| Of_list: 'a list -> t | |
| Of_int: int -> t | |
let of_list list = Of_list list | |
let of_int int = Of_int int | |
let to_int = function | |
| Of_list l -> List.length l | |
| Of_int n -> n | |
let compare t1 t2 = | |
match t1, t2 with | |
| Of_list l1, Of_list l2 -> compare_lengths l1 l2 | |
| Of_list l, Of_int n -> compare_length_with l n | |
| Of_int n, Of_list l -> -1 * compare_length_with l n | |
| Of_int n, Of_int m -> compare n m | |
end | |
let length = Length.of_list | |
end | |
List.length nom_ev > List.length quote_ev | |
Length.(of_list nom_ev > of_list quote_ev) | |
List.compare_lengths nom_ev quote_ev = -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment