Skip to content

Commit 1e28ec5

Browse files
Direct encoding of laws as tests
1 parent 795ea11 commit 1e28ec5

File tree

12 files changed

+196
-403
lines changed

12 files changed

+196
-403
lines changed

proarrow.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ library
107107
Proarrow.Core
108108
Proarrow.Functor
109109
Proarrow.Tools.CCC
110-
Proarrow.Tools.Laws
111110
Proarrow.Monoid
112111
Proarrow.Object
113112
Proarrow.Object.BinaryProduct
@@ -168,6 +167,7 @@ test-suite test
168167
other-modules:
169168
Props
170169
Props.Bool
170+
Props.Free
171171
Props.Hask
172172
Props.Kleisli
173173
Props.Linear

src/Proarrow/Category/Monoidal.hs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Proarrow.Category.Monoidal where
44

55
import Data.Kind (Constraint)
6-
import Prelude (Eq, Show, ($), (++))
6+
import Prelude (Eq, Show, ($))
77

88
import Proarrow.Category.Instance.Free
99
( Elem
@@ -14,13 +14,11 @@ import Proarrow.Category.Instance.Free
1414
, Ok
1515
, WithEq
1616
, WithShow
17-
, emb
1817
)
1918
import Proarrow.Category.Instance.Product ((:**:) (..))
2019
import Proarrow.Category.Instance.Unit qualified as U
2120
import Proarrow.Core (CAT, CategoryOf (..), Kind, Obj, Profunctor (..), Promonad (..), obj, src, tgt, type (+->))
2221
import Proarrow.Functor (FunctorForRep (..))
23-
import Proarrow.Tools.Laws (AssertEq (..), Laws (..), Var, iso)
2422

2523
-- This is equal to a monoidal functor for representable profunctors
2624
-- and to an oplax monoidal functor for corepresentable profunctors.
@@ -209,62 +207,6 @@ deriving instance (WithShow a) => Show (Struct SymMonoidal a b)
209207
instance (Ok cs p, SymMonoidal `Elem` cs, Monoidal `Elem` cs) => SymMonoidal (FREE cs p) where
210208
swap = Str Swap Id
211209

212-
data instance Var '[Monoidal] a b where
213-
F :: Var '[Monoidal] "A" "B"
214-
G :: Var '[Monoidal] "B" "C"
215-
H :: Var '[Monoidal] "C" "D"
216-
deriving instance Show (Var '[Monoidal] a b)
217-
instance Laws '[Monoidal] where
218-
type
219-
EqTypes '[Monoidal] =
220-
'[ EMB "A"
221-
, EMB "B"
222-
, UnitF **! EMB "A"
223-
, UnitF **! EMB "B"
224-
, EMB "A" **! UnitF
225-
, EMB "B" **! UnitF
226-
, EMB "A" **! EMB "B"
227-
, (EMB "A" **! UnitF) **! EMB "B"
228-
, (EMB "A" **! EMB "B") **! EMB "C"
229-
, EMB "A" **! (EMB "B" **! EMB "C")
230-
, (EMB "B" **! EMB "C") **! EMB "D"
231-
, EMB "B" **! (EMB "C" **! EMB "D")
232-
, EMB "A" **! (EMB "B" **! (EMB "C" **! EMB "D"))
233-
, ((EMB "A" **! EMB "B") **! EMB "C") **! EMB "D"
234-
]
235-
laws =
236-
let f = emb F; g = emb G; h = emb H
237-
in iso @((EMB "A" **! EMB "B") **! EMB "C") @(EMB "A" **! (EMB "B" **! EMB "C")) associator associatorInv
238-
++ iso @(UnitF **! EMB "A") @(EMB "A") leftUnitor leftUnitorInv
239-
++ iso @(EMB "A" **! UnitF) @(EMB "A") rightUnitor rightUnitorInv
240-
++ [ associator . ((f `par` g) `par` h) :=: (f `par` (g `par` h)) . associator
241-
, associatorInv . (f `par` (g `par` h)) :=: ((f `par` g) `par` h) . associatorInv
242-
, leftUnitor . (par0 `par` f) :=: f . leftUnitor
243-
, leftUnitorInv . f :=: (par0 `par` f) . leftUnitorInv
244-
, rightUnitor . (f `par` par0) :=: f . rightUnitor
245-
, rightUnitorInv . f :=: (f `par` par0) . rightUnitorInv
246-
, (id `par` leftUnitor) . associator @_ @(EMB "A") @_ @(EMB "B") :=: rightUnitor `par` id
247-
, (id `par` associator @_ @(EMB "B") @(EMB "C") @(EMB "D"))
248-
. associator
249-
. (associator @_ @(EMB "A") @(EMB "B") @(EMB "C") `par` id)
250-
:=: associator . associator
251-
]
252-
253-
data instance Var '[Monoidal, SymMonoidal] a b
254-
deriving instance Show (Var '[Monoidal, SymMonoidal] a b)
255-
instance Laws '[Monoidal, SymMonoidal] where
256-
type
257-
EqTypes '[Monoidal, SymMonoidal] =
258-
'[ EMB "A" **! EMB "B"
259-
, (EMB "A" **! EMB "B") **! EMB "C"
260-
, EMB "B" **! (EMB "C" **! EMB "A")
261-
]
262-
laws =
263-
[ swap @_ @(EMB "B") @(EMB "A") . swap :=: id
264-
, (id `par` swap) . associator . (swap `par` id)
265-
:=: associator . swap . associator @_ @(EMB "A") @(EMB "B") @(EMB "C")
266-
]
267-
268210
data UnitFtor :: () +-> k
269211
instance (Monoidal k) => FunctorForRep (UnitFtor :: () +-> k) where
270212
type UnitFtor @ '() = Unit

src/Proarrow/Object/BinaryCoproduct.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Proarrow.Category.Instance.Free
1616
, Ok
1717
, WithEq
1818
, WithShow
19-
, emb
2019
)
2120
import Proarrow.Category.Instance.Free qualified as F
2221
import Proarrow.Category.Instance.Prof (Prof (..))
@@ -33,7 +32,6 @@ import Proarrow.Profunctor.Corepresentable (Corepresentable (..), withCorepOb)
3332
import Proarrow.Profunctor.Identity (Id (..))
3433
import Proarrow.Profunctor.Product ((:*:) (..))
3534
import Proarrow.Profunctor.Terminal (TerminalProfunctor (..))
36-
import Proarrow.Tools.Laws (AssertEq (..), Laws (..), Var)
3735

3836
infixl 4 ||
3937
infixl 4 |||
@@ -230,17 +228,3 @@ instance (Ok cs p, HasBinaryCoproducts `Elem` cs) => HasBinaryCoproducts (FREE c
230228
lft = Str Lft F.Id
231229
rgt = Str Rgt F.Id
232230
f ||| g = Str (Sum f g) F.Id \\ f \\ g
233-
234-
data instance Var '[HasBinaryCoproducts] a b where
235-
F :: Var '[HasBinaryCoproducts] "A" "C"
236-
G :: Var '[HasBinaryCoproducts] "B" "C"
237-
H :: Var '[HasBinaryCoproducts] "C" "Z"
238-
deriving instance Show (Var '[HasBinaryCoproducts] a b)
239-
instance Laws '[HasBinaryCoproducts] where
240-
type EqTypes '[HasBinaryCoproducts] = '[EMB "A", EMB "B", EMB "C", EMB "Z", EMB "A" + EMB "B"]
241-
laws =
242-
let f = emb F; g = emb G; h = emb H
243-
in [ (f ||| g) . lft :=: f
244-
, (f ||| g) . rgt :=: g
245-
, (h . f) ||| (h . g) :=: h . (f ||| g)
246-
]

src/Proarrow/Object/BinaryProduct.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Proarrow.Category.Instance.Free
1616
, Ok
1717
, WithEq
1818
, WithShow
19-
, emb
2019
)
2120
import Proarrow.Category.Instance.Product (Fst, Snd, (:**:) (..))
2221
import Proarrow.Category.Instance.Prof (Prof (..))
@@ -31,7 +30,6 @@ import Proarrow.Object.Terminal (HasTerminalObject (..), Semicartesian)
3130
import Proarrow.Profunctor.Identity qualified as Id
3231
import Proarrow.Profunctor.Product (prod, (:*:) (..))
3332
import Proarrow.Profunctor.Representable (Representable (..), withRepOb)
34-
import Proarrow.Tools.Laws (AssertEq (..), Laws (..), Var)
3533

3634
infixl 5 &&
3735
infixl 5 &&&
@@ -268,17 +266,3 @@ instance (Ok cs p, HasBinaryProducts `Elem` cs) => HasBinaryProducts (FREE cs p)
268266
fst = Str Fst Id
269267
snd = Str Snd Id
270268
f &&& g = Str (Prd f g) Id \\ f \\ g
271-
272-
data instance Var '[HasBinaryProducts] a b where
273-
F :: Var '[HasBinaryProducts] "A" "B"
274-
G :: Var '[HasBinaryProducts] "A" "C"
275-
H :: Var '[HasBinaryProducts] "Z" "A"
276-
deriving instance Show (Var '[HasBinaryProducts] a b)
277-
instance Laws '[HasBinaryProducts] where
278-
type EqTypes '[HasBinaryProducts] = '[EMB "A", EMB "B", EMB "C", EMB "Z", EMB "B" *! EMB "C"]
279-
laws =
280-
let f = emb F; g = emb G; h = emb H
281-
in [ fst . (f &&& g) :=: f
282-
, snd . (f &&& g) :=: g
283-
, (f . h) &&& (g . h) :=: (f &&& g) . h
284-
]

src/Proarrow/Object/Initial.hs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import Data.Kind (Type)
44
import Data.Void (Void, absurd)
55
import Prelude (Eq, Show, type (~))
66

7-
import Proarrow.Category.Instance.Free (Elem, FREE (..), Free (..), HasStructure (..), IsFreeOb (..), Ok, emb)
7+
import Proarrow.Category.Instance.Free (Elem, FREE (..), Free (..), HasStructure (..), IsFreeOb (..), Ok)
88
import Proarrow.Category.Instance.Product ((:**:) (..))
99
import Proarrow.Category.Instance.Prof (Prof (..))
1010
import Proarrow.Category.Instance.Unit (Unit (..))
1111
import Proarrow.Core (CategoryOf (..), Profunctor (..), Promonad (..), type (+->))
1212
import Proarrow.Object.Terminal (HasTerminalObject (..))
1313
import Proarrow.Profunctor.Initial (InitialProfunctor)
14-
import Proarrow.Tools.Laws (AssertEq (..), Laws (..), Var)
1514

1615
class (CategoryOf k, Ob (InitialObject :: k)) => HasInitialObject k where
1716
type InitialObject :: k
@@ -54,10 +53,3 @@ deriving instance Show (Struct HasInitialObject a b)
5453
instance (Ok cs p, HasInitialObject `Elem` cs) => HasInitialObject (FREE cs p) where
5554
type InitialObject = InitF
5655
initiate = Str Initial Id
57-
58-
data instance Var '[HasInitialObject] a b where
59-
F :: Var '[HasInitialObject] "A" "B"
60-
deriving instance Show (Var '[HasInitialObject] a b)
61-
instance Laws '[HasInitialObject] where
62-
type EqTypes '[HasInitialObject] = '[EMB "B", InitF]
63-
laws = [emb F . initiate :=: initiate]

src/Proarrow/Object/Terminal.hs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ module Proarrow.Object.Terminal where
33
import Data.Kind (Type)
44
import Prelude (Eq, Show, type (~))
55

6-
import Proarrow.Category.Instance.Free (Elem, FREE (..), Free (..), HasStructure (..), IsFreeOb (..), Ok, emb)
6+
import Proarrow.Category.Instance.Free (Elem, FREE (..), Free (..), HasStructure (..), IsFreeOb (..), Ok)
77
import Proarrow.Category.Instance.Product ((:**:) (..))
88
import Proarrow.Category.Instance.Prof (Prof (..))
99
import Proarrow.Category.Instance.Unit qualified as U
1010
import Proarrow.Category.Monoidal (Monoidal (..))
1111
import Proarrow.Core (CategoryOf (..), Profunctor (..), Promonad (..), type (+->))
1212
import Proarrow.Profunctor.Terminal (TerminalProfunctor (..))
13-
import Proarrow.Tools.Laws (AssertEq (..), Laws (..), Var)
1413

1514
class (CategoryOf k, Ob (TerminalObject :: k)) => HasTerminalObject k where
1615
type TerminalObject :: k
@@ -54,10 +53,3 @@ deriving instance Show (Struct HasTerminalObject a b)
5453
instance (Ok cs p, HasTerminalObject `Elem` cs) => HasTerminalObject (FREE cs p) where
5554
type TerminalObject = TermF
5655
terminate = Str Terminate Id
57-
58-
data instance Var '[HasTerminalObject] a b where
59-
F :: Var '[HasTerminalObject] "A" "B"
60-
deriving instance Show (Var '[HasTerminalObject] a b)
61-
instance Laws '[HasTerminalObject] where
62-
type EqTypes '[HasTerminalObject] = '[EMB "A", TermF]
63-
laws = [terminate . emb F :=: terminate]

src/Proarrow/Squares/Limit.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ import Proarrow.Squares
2222
, hId
2323
, hSplitAll
2424
, toRight
25-
, vArr
26-
, vCombine
27-
, vId
28-
, vSplit
29-
, vUnitor
30-
, vUnitorInv
3125
, (===)
3226
, (|||)
3327
)

src/Proarrow/Tools/Laws.hs

Lines changed: 0 additions & 53 deletions
This file was deleted.

test/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Test.Tasty (defaultMain, testGroup)
66
import Prelude
77

88
import Props.Bool qualified as Bool
9+
import Props.Free qualified as Free
910
import Props.Hask qualified as Hask
1011
import Props.Kleisli qualified as Kleisli
1112
import Props.Linear qualified as Linear
@@ -20,6 +21,7 @@ main =
2021
testGroup
2122
"Proarrow"
2223
[ Bool.test
24+
, Free.test
2325
, Hask.test
2426
, Linear.test
2527
, Kleisli.test

0 commit comments

Comments
 (0)