package preface

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

Source file category.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
module Core (Req : Preface_specs.Category.WITH_ID_AND_COMPOSE) :
  Preface_specs.Category.CORE with type ('a, 'b) t = ('a, 'b) Req.t =
  Req

module Operation (Core : Preface_specs.Category.CORE) :
  Preface_specs.Category.OPERATION with type ('a, 'b) t = ('a, 'b) Core.t =
struct
  type ('a, 'b) t = ('a, 'b) Core.t

  let compose_right_to_left f g = Core.compose f g

  let compose_left_to_right f g = Core.compose g f
end

module Infix (Core : Preface_specs.Category.CORE) :
  Preface_specs.Category.INFIX with type ('a, 'b) t = ('a, 'b) Core.t = struct
  type ('a, 'b) t = ('a, 'b) Core.t

  let ( % ) f g = Core.compose f g

  let ( <% ) f g = Core.compose f g

  let ( %> ) f g = Core.compose g f

  let ( <<< ) f g = Core.compose f g

  let ( >>> ) f g = Core.compose g f
end

module Via_id_and_compose (Req : Preface_specs.Category.WITH_ID_AND_COMPOSE) :
  Preface_specs.CATEGORY with type ('a, 'b) t = ('a, 'b) Req.t = struct
  module Core = Core (Req)
  include Core
  include Operation (Core)
  module Infix = Infix (Core)
  include Infix
end

module Via
    (Core : Preface_specs.Category.CORE)
    (Operation : Preface_specs.Category.OPERATION
                   with type ('a, 'b) t = ('a, 'b) Core.t)
    (Infix : Preface_specs.Category.INFIX
               with type ('a, 'b) t = ('a, 'b) Operation.t) :
  Preface_specs.CATEGORY with type ('a, 'b) t = ('a, 'b) Infix.t = struct
  include Core
  include Operation
  include Infix
  module Infix = Infix
end

module From_monad (Monad : Preface_specs.Monad.CORE) :
  Preface_specs.CATEGORY with type ('a, 'b) t = 'a -> 'b Monad.t =
Via_id_and_compose (struct
  type ('a, 'b) t = 'a -> 'b Monad.t

  let id = Monad.return

  let compose f g = Monad.compose_left_to_right g f
end)

module Product (F : Preface_specs.CATEGORY) (G : Preface_specs.CATEGORY) :
  Preface_specs.CATEGORY with type ('a, 'b) t = ('a, 'b) F.t * ('a, 'b) G.t =
Via_id_and_compose (struct
  type ('a, 'b) t = ('a, 'b) F.t * ('a, 'b) G.t

  let id = (F.id, G.id)

  let compose (x1, y1) (x2, y2) = (F.compose x1 x2, G.compose y1 y2)
end)
OCaml

Innovation. Community. Security.