package preface

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

Source file util.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
let swap (a, b) = (b, a)
let assoc ((a, b), c) = (a, (b, c))
let unassoc (a, (b, c)) = ((a, b), c)
let swap_either x = Either.(fold ~left:right ~right:left) x
let curry f x y = f (x, y)
let uncurry f (x, y) = f x y

let assoc_either x =
  let open Either in
  match x with
  | Left (Left a) -> Left a
  | Left (Right b) -> Right (Left b)
  | Right c -> Right (Right c)
;;

let unassoc_either x =
  let open Either in
  match x with
  | Left a -> Left (Left a)
  | Right (Left b) -> Left (Right b)
  | Right (Right c) -> Right c
;;

module Fun = struct
  open Preface_core.Fun.Infix

  type ('a, 'b) t = 'a -> 'b

  module Profunctor = Preface_make.Profunctor.Via_dimap (struct
    type nonrec ('a, 'b) t = ('a, 'b) t

    let dimap x y z = y % z % x
  end)

  module Strong =
    Preface_make.Strong.Over_profunctor_via_fst
      (Profunctor)
      (struct
        type nonrec ('a, 'b) t = ('a, 'b) t

        let fst x (y, z) = (x y, z)
      end)

  module Choice =
    Preface_make.Choice.Over_profunctor_via_left
      (Profunctor)
      (struct
        type nonrec ('a, 'b) t = ('a, 'b) t

        let left f = function
          | Either.Left x -> Either.Left (f x)
          | Either.Right x -> Either.Right x
        ;;
      end)

  module Closed =
    Preface_make.Closed.Over_profunctor_via_closed
      (Profunctor)
      (struct
        type nonrec ('a, 'b) t = ('a, 'b) t

        let closed = Preface_core.Fun.compose_right_to_left
      end)

  module Semigroupoid = Preface_make.Semigroupoid.Via_compose (struct
    type nonrec ('a, 'b) t = ('a, 'b) t

    let compose = Preface_core.Fun.compose_right_to_left
  end)

  module Category =
    Preface_make.Category.Over_semigroupoid
      (Semigroupoid)
      (struct
        type nonrec ('a, 'b) t = ('a, 'b) t

        let id x = x
      end)

  module Arrow = Preface_make.Arrow.From_strong_and_category (Strong) (Category)

  module Arrow_choice =
    Preface_make.Arrow_choice.Over_arrow_with_choose
      (Arrow)
      (struct
        type nonrec ('a, 'b) t = ('a, 'b) t

        let case f g = Stdlib.Either.fold ~left:f ~right:g
        let choose f g = case (Stdlib.Either.left % f) (Stdlib.Either.right % g)
      end)

  module Arrow_apply =
    Preface_make.Arrow_apply.Over_arrow
      (Arrow)
      (struct
        type nonrec ('a, 'b) t = ('a, 'b) t

        let apply (f, x) = f x
      end)
end

module Endo (T : Preface_specs.Types.T0) =
Preface_make.Monoid.Via_combine_and_neutral (struct
  open Preface_core.Fun.Infix

  type t = T.t -> T.t

  let neutral x = x
  let combine f g = f % g
end)

module Dual (T : Preface_specs.MONOID) =
Preface_make.Monoid.Via_combine_and_neutral (struct
  type t = T.t

  let neutral = T.neutral
  let combine a b = T.combine b a
end)

module Id = struct
  type 'a t = 'a

  module Functor = Preface_make.Functor.Via_map (struct
    type nonrec 'a t = 'a t

    let map f x = f x
  end)

  module Applicative = Preface_make.Applicative.Via_pure_and_apply (struct
    type nonrec 'a t = 'a t

    let pure x = x
    let apply f x = f x
  end)

  module Monad = Preface_make.Monad.Via_return_and_bind (struct
    type nonrec 'a t = 'a t

    let return x = x
    let bind f x = f x
  end)
end
OCaml

Innovation. Community. Security.