Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 161 lines (125 sloc) 4.184 kb
542f90d @sjoerdvisscher Add NoImplicitPrelude to every file so they work in ghci.
authored
1 {-# LANGUAGE TypeFamilies, GADTs, TypeOperators, ScopedTypeVariables, UndecidableInstances, NoImplicitPrelude #-}
8ed42ad @sjoerdvisscher Added more documentation, and file headers.
authored
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Data.Category.Boolean
5 -- License : BSD-style (see the file LICENSE)
6 --
7 -- Maintainer : sjoerd@w3future.com
8 -- Stability : experimental
9 -- Portability : non-portable
3e9eba7 @sjoerdvisscher Made natural transformations part of the Category module.
authored
10 --
76c13a5 @sjoerdvisscher Turn most type families into associated ones.
authored
11 -- /2/, or the Boolean category.
3e9eba7 @sjoerdvisscher Made natural transformations part of the Category module.
authored
12 -- It contains 2 objects, one for true and one for false.
13 -- It contains 3 arrows, 2 identity arrows and one from false to true.
8ed42ad @sjoerdvisscher Added more documentation, and file headers.
authored
14 -----------------------------------------------------------------------------
f55a52c @sjoerdvisscher First commit
authored
15 module Data.Category.Boolean where
16
17 import Data.Category
7625a7c @sjoerdvisscher Some fun with natural transformations.
authored
18 import Data.Category.Functor
19 import Data.Category.NaturalTransformation
20 import Data.Category.Product
28b7d57 @sjoerdvisscher Refactoring and renaming of limits. Example:
authored
21 import Data.Category.Limit
2a93bad @sjoerdvisscher Monoids and comonoids in Boolean.
authored
22 import Data.Category.Monoidal
fa2fcf7 @sjoerdvisscher The Boolean category is cartesian closed.
authored
23 import Data.Category.CartesianClosed
f55a52c @sjoerdvisscher First commit
authored
24
25
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
26 data Fls
27 data Tru
24ec528 @sjoerdvisscher Complete rewrite.
authored
28
29 data Boolean a b where
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
30 Fls :: Boolean Fls Fls
31 F2T :: Boolean Fls Tru
32 Tru :: Boolean Tru Tru
3e9eba7 @sjoerdvisscher Made natural transformations part of the Category module.
authored
33
6a92deb @sjoerdvisscher Added documentation.
authored
34 -- | @Boolean@ is the category with true and false as objects, and an arrow from false to true.
86b4858 @sjoerdvisscher Added a Category class with natural transformation Id -> Id.
authored
35 instance Category Boolean where
24ec528 @sjoerdvisscher Complete rewrite.
authored
36
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
37 src Fls = Fls
38 src F2T = Fls
39 src Tru = Tru
24ec528 @sjoerdvisscher Complete rewrite.
authored
40
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
41 tgt Fls = Fls
42 tgt F2T = Tru
43 tgt Tru = Tru
f55a52c @sjoerdvisscher First commit
authored
44
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
45 Fls . Fls = Fls
46 F2T . Fls = F2T
47 Tru . F2T = F2T
48 Tru . Tru = Tru
f55a52c @sjoerdvisscher First commit
authored
49
50
6a92deb @sjoerdvisscher Added documentation.
authored
51 -- | False is the initial object in the Boolean category.
28b7d57 @sjoerdvisscher Refactoring and renaming of limits. Example:
authored
52 instance HasInitialObject Boolean where
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
53 type InitialObject Boolean = Fls
24ec528 @sjoerdvisscher Complete rewrite.
authored
54 initialObject = Fls
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
55 initialize Fls = Fls
56 initialize Tru = F2T
24ec528 @sjoerdvisscher Complete rewrite.
authored
57
6a92deb @sjoerdvisscher Added documentation.
authored
58 -- | True is the terminal object in the Boolean category.
28b7d57 @sjoerdvisscher Refactoring and renaming of limits. Example:
authored
59 instance HasTerminalObject Boolean where
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
60 type TerminalObject Boolean = Tru
24ec528 @sjoerdvisscher Complete rewrite.
authored
61 terminalObject = Tru
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
62 terminate Fls = F2T
63 terminate Tru = Tru
f55a52c @sjoerdvisscher First commit
authored
64
65
876f332 @sjoerdvisscher Added more documentation.
authored
66 -- | Conjunction is the binary product in the Boolean category.
76c13a5 @sjoerdvisscher Turn most type families into associated ones.
authored
67 instance HasBinaryProducts Boolean where
68
69 type BinaryProduct Boolean Fls Fls = Fls
70 type BinaryProduct Boolean Fls Tru = Fls
71 type BinaryProduct Boolean Tru Fls = Fls
72 type BinaryProduct Boolean Tru Tru = Tru
24ec528 @sjoerdvisscher Complete rewrite.
authored
73
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
74 proj1 Fls Fls = Fls
75 proj1 Fls Tru = Fls
76 proj1 Tru Fls = F2T
77 proj1 Tru Tru = Tru
78 proj2 Fls Fls = Fls
79 proj2 Fls Tru = F2T
80 proj2 Tru Fls = Fls
81 proj2 Tru Tru = Tru
82
83 Fls &&& Fls = Fls
84 Fls &&& F2T = Fls
85 F2T &&& Fls = Fls
86 F2T &&& F2T = F2T
87 Tru &&& Tru = Tru
24ec528 @sjoerdvisscher Complete rewrite.
authored
88
89
a7978de @sjoerdvisscher More documentation.
authored
90 -- | Disjunction is the binary coproduct in the Boolean category.
76c13a5 @sjoerdvisscher Turn most type families into associated ones.
authored
91 instance HasBinaryCoproducts Boolean where
92
93 type BinaryCoproduct Boolean Fls Fls = Fls
94 type BinaryCoproduct Boolean Fls Tru = Tru
95 type BinaryCoproduct Boolean Tru Fls = Tru
96 type BinaryCoproduct Boolean Tru Tru = Tru
24ec528 @sjoerdvisscher Complete rewrite.
authored
97
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
98 inj1 Fls Fls = Fls
99 inj1 Fls Tru = F2T
100 inj1 Tru Fls = Tru
101 inj1 Tru Tru = Tru
102 inj2 Fls Fls = Fls
103 inj2 Fls Tru = Tru
104 inj2 Tru Fls = F2T
105 inj2 Tru Tru = Tru
d886c54 @sjoerdvisscher Added :+: and :*: functors which are the binary (co)products in the f…
authored
106
5613811 @sjoerdvisscher Represent objects at value level with their identity functions.
authored
107 Fls ||| Fls = Fls
108 F2T ||| F2T = F2T
109 F2T ||| Tru = Tru
110 Tru ||| F2T = Tru
111 Tru ||| Tru = Tru
7625a7c @sjoerdvisscher Some fun with natural transformations.
authored
112
113
876f332 @sjoerdvisscher Added more documentation.
authored
114 -- | Implication makes the Boolean category cartesian closed.
fa2fcf7 @sjoerdvisscher The Boolean category is cartesian closed.
authored
115 instance CartesianClosed Boolean where
116
76c13a5 @sjoerdvisscher Turn most type families into associated ones.
authored
117 type Exponential Boolean Fls Fls = Tru
118 type Exponential Boolean Fls Tru = Tru
119 type Exponential Boolean Tru Fls = Fls
120 type Exponential Boolean Tru Tru = Tru
121
fa2fcf7 @sjoerdvisscher The Boolean category is cartesian closed.
authored
122 apply Fls Fls = Fls
123 apply Fls Tru = F2T
124 apply Tru Fls = Fls
125 apply Tru Tru = Tru
126
127 tuple Fls Fls = F2T
128 tuple Fls Tru = Tru
129 tuple Tru Fls = Fls
130 tuple Tru Tru = Tru
131
132 Fls ^^^ Fls = Tru
133 Fls ^^^ F2T = F2T
134 Fls ^^^ Tru = Fls
135 F2T ^^^ Fls = Tru
136 F2T ^^^ F2T = F2T
137 F2T ^^^ Tru = F2T
138 Tru ^^^ Fls = Tru
139 Tru ^^^ F2T = Tru
140 Tru ^^^ Tru = Tru
141
142
2a93bad @sjoerdvisscher Monoids and comonoids in Boolean.
authored
143 trueProductMonoid :: MonoidObject (ProductFunctor Boolean) Tru
144 trueProductMonoid = MonoidObject Tru Tru
145
146 falseCoproductComonoid :: ComonoidObject (CoproductFunctor Boolean) Fls
147 falseCoproductComonoid = ComonoidObject Fls Fls
148
149 trueProductComonoid :: ComonoidObject (ProductFunctor Boolean) Tru
150 trueProductComonoid = ComonoidObject Tru Tru
151
152 falseCoproductMonoid :: MonoidObject (CoproductFunctor Boolean) Fls
153 falseCoproductMonoid = MonoidObject Fls Fls
154
155 trueCoproductMonoid :: MonoidObject (CoproductFunctor Boolean) Tru
156 trueCoproductMonoid = MonoidObject F2T Tru
157
158 falseProductComonoid :: ComonoidObject (ProductFunctor Boolean) Fls
159 falseProductComonoid = ComonoidObject F2T Fls
160
Something went wrong with that request. Please try again.