Source file abstract_algebra.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

open Base

module Commutative_group = struct
  (** An implementation of this interface should have the following properties:

      + associativity: [(a + b) + c = a + (b + c)]
      + identity: [zero + a = a + zero = a]
      + inverses: given any [a] there exists a (unique) elt [b] such that [a + b = b + a =
      zero]
      + commutativity: [a + b = b + a]
  *)

  module type Without_sexp = sig
    type t

    val zero : t
    val (+)  : t -> t -> t
    val (-)  : t -> t -> t
  end

  module type S = sig
    type t [@@deriving sexp]
    include Without_sexp with type t := t
  end
end

module Vector_space = struct
  module type S = sig
    type t
    include Commutative_group.S with type t := t
    val scale : t -> float -> t
  end
end