aboutsummaryrefslogtreecommitdiff
path: root/dataType.ml
blob: b6c4fd0025d4018ef12816ba2abf910a629bcec9 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module type COMPARABLE = sig
  type t
  val eq: t -> t -> bool
  val neq: t -> t -> bool
  val lt: t -> t -> bool
  val le: t -> t -> bool
  val gt: t -> t -> bool
  val ge: t -> t -> bool
end

module Comparable = struct

  let eq = (=)
  let neq = (<>)
  let lt = (<)
  let le = (<=)
  let gt = (>)
  let ge = (>=)

end

module Num = struct

  let rnd () =
    let value = Random.bits () in
    Q.make (Z.of_int value) (Z.of_int (1 lsl 30))

  include Q

  let eq = Q.equal

  let neq a b = not (Q.equal a b)

  let mult = Q.mul

  let floor f = Q.of_bigint (Q.to_bigint f)

  let ge = Q.geq

  let ge = Q.geq

  let le = Q.leq

  let pow t q_factor =
    let factor = Q.to_int q_factor
    and num = Q.num t
    and den = Q.num t in

    Q.make (Z.pow num factor) (Z.pow den factor)

  let gcd t1 t2 =
    Q.of_bigint @@ Z.gcd (Q.to_bigint t1) (Q.to_bigint t2)

  let lcm t1 t2 =
    Q.of_bigint @@ Z.lcm (Q.to_bigint t1) (Q.to_bigint t2)

  let is_integer t = (Q.den t) == Z.one

end

module Bool = struct

  type t = bool
  include Comparable

  let true_ = true
  let false_ = false

  let or_ = (||)
  let and_ = (&&)
  let not = Pervasives.not

end

module String = struct

  type t = UTF8.t
  include Comparable

end

module Date = Date.Make(Num)