package prbnmcn-basic-structures

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

Source file std.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
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
(** Extension of basic modules making them compatible with the [Std] module type *)

open Intf_std

module Bool = struct
  include Bool

  let hash = function false -> 0 | true -> 1

  let pp = Format.pp_print_bool
end

module _ : Std with type t = bool = Bool

module Int = struct
  include Int

  let hash (i : int) = i

  let pp = Format.pp_print_int
end

module _ : Std with type t = int = Int

module Float = struct
  include Float

  let pp = Format.pp_print_float
end

module _ : Std with type t = float = Float

module Complex = struct
  include Complex

  let pp fmtr { Complex.re; im } =
    Format.fprintf fmtr "@[{ re = %f; im = %f }@]" re im

  let hash { Complex.re; im } = Hashtbl.hash (re, im) [@@inline]

  let equal (x : Complex.t) (y : Complex.t) = x = y [@@inline]

  let compare (x : Complex.t) (y : Complex.t) =
    let c = Float.compare x.re y.re in
    if c <> 0 then c else Float.compare x.im y.im
    [@@inline]
end

module _ : Std with type t = float = Float

module String = struct
  include String

  let hash = Hashtbl.hash

  let pp = Format.pp_print_string
end

module _ : Std with type t = string = String

module Z = struct
  include Z

  let pp = pp_print
end

module _ : Std with type t = Z.t = Z

module Q = struct
  include Q

  let hash = Hashtbl.hash

  let pp = pp_print
end

module _ : Std with type t = Q.t = Q
OCaml

Innovation. Community. Security.