package containers

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file CCEqual.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(* This file is free software, part of containers. See file "license" for more details. *)

(** {1 Equality Combinators} *)

type 'a t = 'a -> 'a -> bool

let poly = Stdlib.( = )
let physical = Stdlib.( == )
let int : int t = ( = )
let string : string t = Stdlib.( = )
let bool : bool t = Stdlib.( = )
let float : float t = Stdlib.( = )
let unit () () = true

let rec list f l1 l2 =
  match l1, l2 with
  | [], [] -> true
  | [], _ | _, [] -> false
  | x1 :: l1', x2 :: l2' -> f x1 x2 && list f l1' l2'

let array eq a b =
  let rec aux i =
    if i = Array.length a then
      true
    else
      eq a.(i) b.(i) && aux (i + 1)
  in
  Array.length a = Array.length b && aux 0

let option f o1 o2 =
  match o1, o2 with
  | None, None -> true
  | Some _, None | None, Some _ -> false
  | Some x, Some y -> f x y

let pair f g (x1, y1) (x2, y2) = f x1 x2 && g y1 y2
let triple f g h (x1, y1, z1) (x2, y2, z2) = f x1 x2 && g y1 y2 && h z1 z2
let map f eq x y = eq (f x) (f y)
let always_eq _ _ = true
let never_eq _ _ = false

module Infix = struct
  let ( >|= ) x f = map f x
end

include Infix
OCaml

Innovation. Community. Security.