Source file strong.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
let swap (x, y) = (y, x)
module Snd_via_fst
(D : Preface_specs.Profunctor.WITH_DIMAP)
(F : Preface_specs.Strong.WITH_FST with type ('a, 'b) t = ('a, 'b) D.t) =
struct
type ('a, 'b) t = ('a, 'b) F.t
let snd x = D.dimap swap swap (F.fst x)
end
module Fst_via_snd
(D : Preface_specs.Profunctor.WITH_DIMAP)
(S : Preface_specs.Strong.WITH_SND with type ('a, 'b) t = ('a, 'b) D.t) =
struct
type ('a, 'b) t = ('a, 'b) S.t
let fst x = D.dimap swap swap (S.snd x)
end
module Core_via_dimap_and_fst (Req : Preface_specs.Strong.WITH_DIMAP_AND_FST) =
struct
include Req
module C = Profunctor.Core_via_dimap (Req)
include C
include Snd_via_fst (C) (Req)
end
module Core_via_dimap_and_snd (Req : Preface_specs.Strong.WITH_DIMAP_AND_SND) =
struct
include Req
module C = Profunctor.Core_via_dimap (Req)
include C
include Fst_via_snd (C) (Req)
end
module Core_via_contramap_fst_and_map_snd_and_fst
(Req : Preface_specs.Strong.WITH_CONTRAMAP_FST_AND_MAP_SND_AND_FST) =
struct
include Req
module C = Profunctor.Core_via_contramap_fst_and_map_snd (Req)
include C
include Snd_via_fst (C) (Req)
end
module Core_via_contramap_fst_and_map_snd_and_snd
(Req : Preface_specs.Strong.WITH_CONTRAMAP_FST_AND_MAP_SND_AND_SND) =
struct
include Req
module C = Profunctor.Core_via_contramap_fst_and_map_snd (Req)
include C
include Fst_via_snd (C) (Req)
end
module Core_over_profunctor_via_fst
(P : Preface_specs.Profunctor.CORE)
(F : Preface_specs.Strong.WITH_FST with type ('a, 'b) t = ('a, 'b) P.t) =
struct
include P
include F
include Snd_via_fst (P) (F)
end
module Core_over_profunctor_via_snd
(P : Preface_specs.Profunctor.CORE)
(S : Preface_specs.Strong.WITH_SND with type ('a, 'b) t = ('a, 'b) P.t) =
struct
include P
include S
include Fst_via_snd (P) (S)
end
module Operation (Core : Preface_specs.Strong.CORE) = struct
type ('a, 'b) t = ('a, 'b) Core.t
let uncurry x = Core.map_snd (fun (f, x) -> f x) (Core.fst x)
let strong f x =
Core.dimap (fun x -> (x, x)) (fun (x, y) -> f y x) (Core.fst x)
;;
end
module Via
(Core : Preface_specs.Strong.CORE)
(Operation : Preface_specs.Strong.OPERATION) =
struct
include Core
include Operation
end
module Via_dimap_and_fst (Req : Preface_specs.Strong.WITH_DIMAP_AND_FST) =
struct
module Core = Core_via_dimap_and_fst (Req)
module Operation = Operation (Core)
include Core
include Operation
end
module Via_dimap_and_snd (Req : Preface_specs.Strong.WITH_DIMAP_AND_SND) =
struct
module Core = Core_via_dimap_and_snd (Req)
module Operation = Operation (Core)
include Core
include Operation
end
module Via_contramap_fst_and_map_snd_and_fst
(Req : Preface_specs.Strong.WITH_CONTRAMAP_FST_AND_MAP_SND_AND_FST) =
struct
module Core = Core_via_contramap_fst_and_map_snd_and_fst (Req)
module Operation = Operation (Core)
include Core
include Operation
end
module Via_contramap_fst_and_map_snd_and_snd
(Req : Preface_specs.Strong.WITH_CONTRAMAP_FST_AND_MAP_SND_AND_SND) =
struct
module Core = Core_via_contramap_fst_and_map_snd_and_snd (Req)
module Operation = Operation (Core)
include Core
include Operation
end
module Over_profunctor_via_fst
(P : Preface_specs.PROFUNCTOR)
(F : Preface_specs.Strong.WITH_FST with type ('a, 'b) t = ('a, 'b) P.t) =
struct
module Core = Core_over_profunctor_via_fst (P) (F)
include Core
include Operation (Core)
end
module Over_profunctor_via_snd
(P : Preface_specs.PROFUNCTOR)
(S : Preface_specs.Strong.WITH_SND with type ('a, 'b) t = ('a, 'b) P.t) =
struct
module Core = Core_over_profunctor_via_snd (P) (S)
include Core
include Operation (Core)
end
module From_monad (Monad : Preface_specs.Monad.CORE) = struct
module Prof = Profunctor.From_functor (Monad)
include
Over_profunctor_via_fst
(Prof)
(struct
type ('a, 'b) t = 'a -> 'b Monad.t
let fst f (a, c) =
let open Monad in
bind (fun b -> return (b, c)) (f a)
;;
end)
end
module From_functor (Functor : Preface_specs.Functor.CORE) = struct
module Prof = Profunctor.From_functor (Functor)
include
Over_profunctor_via_fst
(Prof)
(struct
type ('a, 'b) t = 'a -> 'b Functor.t
let fst f (a, c) = Functor.map (fun x -> (x, c)) (f a)
end)
end
module Composition (F : Preface_specs.STRONG) (G : Preface_specs.STRONG) =
struct
module P = Profunctor.Composition (F) (G)
type ('a, 'b) t = ('a, 'b) P.t =
| Composed : (('a, 'b) F.t * ('b, 'c) G.t) -> ('a, 'c) t
include (
Over_profunctor_via_fst
(P)
(struct
type nonrec ('a, 'b) t = ('a, 'b) t
let fst (Composed (x, y)) = Composed (F.fst x, G.fst y)
end) :
Preface_specs.STRONG with type ('a, 'b) t := ('a, 'b) t )
end