Skip to content

Commit c28b96f

Browse files
committedApr 25, 2018
Check more laws
1 parent 2e82d90 commit c28b96f

10 files changed

+424
-35
lines changed
 

Diff for: ‎lib/Applicative.hs

+113
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ module Applicative
66
, law_Applicative_comp
77
, law_Applicative_homo
88
, law_Applicative_inter
9+
, law_Applicative_id'
10+
, law_Applicative_id_left'
11+
, law_Applicative_id_right'
12+
, law_Applicative_assoc'
913
, (<$>)
1014
, ZipList(..)
1115
) where
@@ -96,6 +100,109 @@ law_Applicative_inter :: (Applicative f, Dom f ~ Cod f, Cod f ~ (->))
96100
=> f (Dom f a b) -> a -> Equal (f b)
97101
law_Applicative_inter fs x = (fs <*> pure x) `equal` (pure ($ x) <*> fs)
98102

103+
-- f :: a -> b
104+
-- x :: a
105+
-- liftA2' (\((), x) -> f x) (pure (), xs) = fmap f xs
106+
law_Applicative_id' :: forall f a b k p u l q.
107+
( Applicative f
108+
, Cartesian (Dom f), Cartesian (Cod f)
109+
, Obj (Dom f) a, Obj (Dom f) b
110+
, Cod f ~ (->)
111+
, k ~ Dom f, p ~ Prod k, u ~ Unit p
112+
, l ~ Cod f, q ~ Prod l
113+
) => a `k` b -> f a -> Equal (f b)
114+
law_Applicative_id' f xs =
115+
liftA2' f' xs' `equal` fmap f xs
116+
where
117+
f' :: p u a `k` b
118+
f' = unapply (\p -> let (_, x) = unprod p in f `apply` x)
119+
\\ (proveCartesian @k :: (Obj k u, Obj k a) :- Obj k (p u a))
120+
xs' :: q (f u) (f a)
121+
xs' = prod (pure (punit @p), xs)
122+
123+
-- f :: (a, b) -> c
124+
-- x :: a
125+
-- ys :: f b
126+
-- liftA2' f (pure x, ys) = fmap (\x -> f (x, y)) ys
127+
law_Applicative_id_left' ::
128+
forall f a b c k p.
129+
( Applicative f, Cartesian (Dom f), Cartesian (Cod f)
130+
, Obj (Dom f) a, Obj (Dom f) b, Obj (Dom f) c
131+
, Cod f ~ (->)
132+
, k ~ Dom f, p ~ Prod k
133+
) => p a b `k` c -> a -> f b -> Equal (f c)
134+
law_Applicative_id_left' f x ys =
135+
liftA2' f (prod (pure x, ys)) `equal`
136+
fmap (unapply (\y -> f `apply` prod (x, y))) ys
137+
\\ (proveCartesian @k :: (Obj k a, Obj k b) :- Obj k (p a b))
138+
139+
-- liftA2' f (xs, pure y) = fmap (\y -> f (x, y)) xs
140+
-- f :: (a, b) -> c
141+
-- xs :: f a
142+
-- y :: b
143+
law_Applicative_id_right' ::
144+
forall f a b c k p.
145+
( Applicative f, Cartesian (Dom f), Cartesian (Cod f)
146+
, Obj (Dom f) a, Obj (Dom f) b, Obj (Dom f) c
147+
, Cod f ~ (->)
148+
, k ~ Dom f, p ~ Prod k
149+
) => p a b `k` c -> f a -> b -> Equal (f c)
150+
law_Applicative_id_right' f xs y =
151+
liftA2' f (prod (xs, pure y)) `equal`
152+
fmap (unapply (\x -> f `apply` prod (x, y))) xs
153+
\\ (proveCartesian @k :: (Obj k a, Obj k b) :- Obj k (p a b))
154+
155+
-- f :: a -> a'
156+
-- g :: b -> b'
157+
-- h :: c -> c'
158+
-- i :: (a', (b', c')) -> d
159+
-- liftA2' hi (liftA2' fg (xs, ys), zs) = liftA2' fi (xs, liftA2' gh (ys, zs))
160+
law_Applicative_assoc' ::
161+
forall f a a' b b' c c' d k p.
162+
( Applicative f, Cartesian (Dom f), Cartesian (Cod f)
163+
, Obj (Dom f) a, Obj (Dom f) b, Obj (Dom f) c, Obj (Dom f) d
164+
, Obj (Dom f) a', Obj (Dom f) b', Obj (Dom f) c'
165+
, Cod f ~ (->)
166+
, k ~ Dom f, p ~ Prod k
167+
) => a `k` a' -> b `k` b' -> c `k` c' -> (p a' (p b' c')) `k` d ->
168+
f a -> f b -> f c -> Equal (f d)
169+
law_Applicative_assoc' f g h i xs ys zs =
170+
liftA2' hi (liftA2' fg (xs, ys), zs) `equal`
171+
liftA2' fi (xs, liftA2' gh (ys, zs))
172+
\\ (proveCartesian @k :: (Obj k a', Obj k b') :- Obj k (p a' b'))
173+
\\ (proveCartesian @k :: (Obj k b', Obj k c') :- Obj k (p b' c'))
174+
where fg :: p a b `k` p a' b'
175+
fg = unapply (\p -> let (x, y) = unprod p
176+
in prod (f `apply` x, g `apply` y))
177+
\\ (proveCartesian @k :: (Obj k a, Obj k b) :- Obj k (p a b))
178+
\\ (proveCartesian @k :: (Obj k a', Obj k b') :- Obj k (p a' b'))
179+
hi :: p (p a' b') c `k` d
180+
hi = unapply (\p -> let (q', z) = unprod p
181+
(x', y') = unprod q'
182+
r' = prod (x', prod (y', h `apply` z))
183+
in i `apply` r')
184+
\\ (proveCartesian @k ::
185+
(Obj k (p a' b'), Obj k c) :- Obj k (p (p a' b') c))
186+
\\ (proveCartesian @k :: (Obj k a', Obj k b') :- Obj k (p a' b'))
187+
\\ (proveCartesian @k ::
188+
(Obj k a', Obj k (p b' c')) :- Obj k (p a' (p b' c')))
189+
\\ (proveCartesian @k :: (Obj k b', Obj k c') :- Obj k (p b' c'))
190+
gh :: p b c `k` p b' c'
191+
gh = unapply (\p -> let (y, z) = unprod p
192+
in prod (g `apply` y, h `apply` z))
193+
\\ (proveCartesian @k :: (Obj k b, Obj k c) :- Obj k (p b c))
194+
\\ (proveCartesian @k :: (Obj k b', Obj k c') :- Obj k (p b' c'))
195+
fi :: p a (p b' c') `k` d
196+
fi = unapply (\p -> let (x, q') = unprod p
197+
(y', z') = unprod q'
198+
r' = prod (f `apply` x, prod (y', z'))
199+
in i `apply` r')
200+
\\ (proveCartesian @k ::
201+
(Obj k a, Obj k (p b' c')) :- Obj k (p a (p b' c')))
202+
\\ (proveCartesian @k ::
203+
(Obj k a', Obj k (p b' c')) :- Obj k (p a' (p b' c')))
204+
\\ (proveCartesian @k :: (Obj k b', Obj k c') :- Obj k (p b' c'))
205+
99206

100207

101208
infixl 4 <$>
@@ -175,3 +282,9 @@ instance Applicative ZipList where
175282
in ZipList (f x y : rs)
176283
liftA2 _ _ _ = ZipList []
177284
-- liftA2 f (ZipList xs) (ZipList ys) = ZipList (zipWith f xs ys)
285+
286+
instance Applicative NList where
287+
pure x = NList [x]
288+
(<*>) = undefined
289+
liftA2' f (NList xs, NList ys) =
290+
NList [f `apply` NProd x y | x <- xs, y <- ys]

Diff for: ‎lib/Category.hs

+87-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{-# LANGUAGE UndecidableInstances #-}
2+
{-# LANGUAGE UndecidableSuperClasses #-}
3+
14
module Category
25
( Equal(..)
36
, equal
@@ -17,6 +20,8 @@ module Category
1720
, Closed(..)
1821
, Hask
1922
, type (-#>)(..)
23+
, type (*#*)(..), NUnit(..)
24+
-- , type (+#+)(..), NCounit()
2025
) where
2126

2227
import Prelude hiding (id, (.), curry, uncurry)
@@ -25,6 +30,8 @@ import qualified Prelude
2530
import Data.Constraint
2631
import Data.Kind
2732
import Data.Void
33+
import GHC.Generics
34+
import qualified Test.QuickCheck as QC
2835

2936

3037

@@ -99,7 +106,8 @@ class CatProd (p :: ProdKind) where
99106
-- preassoc p = let (q, z) = unprod p
100107
-- (x, y) = unprod q
101108
-- in prod (x, prod (y, z))
102-
class (Category k, CatProd (Prod k)) => Cartesian k where
109+
class (Category k, CatProd (Prod k), Obj k (Unit (Prod k)))
110+
=> Cartesian k where
103111
type Prod k :: ProdKind
104112
proveCartesian :: (Obj k a, Obj k b) :- Obj k (Prod k a b)
105113

@@ -114,7 +122,8 @@ class CatCoprod (p :: CoprodKind) where
114122
-- => p a (p b c) -> p (p a b) c
115123
-- recoassoc :: (Obj k a, Obj k b, Obj k c, p ~ Coprod k)
116124
-- => p (p a b) c -> p a (p b c)
117-
class (Category k, CatCoprod (Coprod k)) => Cocartesian k where
125+
class (Category k, CatCoprod (Coprod k), Obj k (Counit (Coprod k)))
126+
=> Cocartesian k where
118127
type Coprod k :: Type -> Type -> Type
119128
proveCocartesian :: (Obj k a, Obj k b) :- Obj k (Coprod k a b)
120129

@@ -174,9 +183,85 @@ instance Closed (->) where
174183
-- | Num is a category
175184
newtype (-#>) a b = NFun { unNFun :: (Num a, Num b) => a -> b }
176185

186+
data (*#*) a b = NProd a b
187+
deriving (Eq, Ord, Read, Show, Generic)
188+
instance QC.Arbitrary (a, b) => QC.Arbitrary (a *#* b) where
189+
arbitrary = prod Prelude.<$> QC.arbitrary
190+
shrink p = prod Prelude.<$> QC.shrink (unprod p)
191+
instance (QC.CoArbitrary a, QC.CoArbitrary b) => QC.CoArbitrary (a *#* b)
192+
instance QC.Function (a, b) => QC.Function (a *#* b) where
193+
function = QC.functionMap unprod prod
194+
195+
instance (Num a, Num b) => Num (a *#* b) where
196+
NProd x1 x2 + NProd y1 y2 = NProd (x1 + y1) (x2 + y2)
197+
NProd x1 x2 * NProd y1 y2 = NProd (x1 * y1) (x2 * y2)
198+
negate (NProd x y) = NProd (negate x) (negate y)
199+
abs (NProd x y) = NProd (abs x) (abs y)
200+
signum (NProd x y) = NProd (signum x) (signum y)
201+
fromInteger n = NProd (fromInteger n) (fromInteger n)
202+
203+
data NUnit = NUnit
204+
deriving (Eq, Ord, Read, Show, Generic)
205+
206+
instance QC.Arbitrary NUnit where
207+
arbitrary = return NUnit
208+
shrink NUnit = []
209+
instance QC.CoArbitrary NUnit
210+
instance QC.Function NUnit where
211+
function = QC.functionMap (const ()) (const NUnit)
212+
213+
instance Num NUnit where
214+
NUnit + NUnit = NUnit
215+
NUnit * NUnit = NUnit
216+
negate NUnit = NUnit
217+
abs NUnit = NUnit
218+
signum NUnit = NUnit
219+
fromInteger _ = NUnit
220+
177221
instance Category (-#>) where
178222
type Obj (-#>) = Num
179223
id = NFun id
180224
NFun g . NFun f = NFun (g . f)
181225
apply = unNFun
182226
unapply = NFun
227+
228+
instance CatProd (*#*) where
229+
type Unit (*#*) = NUnit
230+
punit = NUnit
231+
prod (a, b) = NProd a b
232+
unprod (NProd a b) = (a, b)
233+
234+
instance Cartesian (-#>) where
235+
type Prod (-#>) = (*#*)
236+
proveCartesian = Sub Dict
237+
238+
-- data (+#+) a b = NLeft a | NRight b
239+
-- deriving (Eq, Ord, Read, Show)
240+
-- instance (Num a, Num b) => Num (a +#+ b) where
241+
-- NLeft x + NLeft y = NLeft (x + y)
242+
-- NRight x + NRight y = NRight (x + y)
243+
-- NLeft x + _ = NLeft x
244+
-- _ + NLeft y = NLeft y
245+
-- NLeft x * NLeft y = NLeft (x * y)
246+
-- NRight x * NRight y = NRight (x * y)
247+
-- NLeft x * _ = NLeft x
248+
-- _ * NLeft y = NLeft y
249+
-- negate (NLeft x) = NLeft (negate x)
250+
-- negate (NRight x) = NRight (negate x)
251+
-- abs (NLeft x) = NLeft (abs x)
252+
-- abs (NRight x) = NRight (abs x)
253+
-- signum (NLeft x) = NLeft (signum x)
254+
-- signum (NRight x) = NRight (signum x)
255+
-- fromInteger n = NLeft (fromInteger n)
256+
--
257+
-- data NCounit
258+
-- instance CatCoprod (+#+) where
259+
-- type Counit (+#+) = NCounit
260+
-- coprod (Left a) = NLeft a
261+
-- coprod (Right b) = NRight b
262+
-- uncoprod (NLeft a) = Left a
263+
-- uncoprod (NRight b) = Right b
264+
--
265+
-- instance Cocartesian (-#>) where
266+
-- type Coprod (-#>) = (+#+)
267+
-- proveCocartesian = Sub Dict

Diff for: ‎lib/Comonad.hs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Comonad
88
import Prelude hiding ( id, (.), curry, uncurry
99
, Functor(..)
1010
)
11+
1112
import Data.Functor.Identity
1213
import Data.Functor.Product as F
1314
import Data.Functor.Sum as F

Diff for: ‎lib/Functor.hs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Functor
44
( Functor(..)
55
, law_Functor_id
66
, law_Functor_assoc
7+
, NList(..)
78
) where
89

910
import Prelude hiding ( id, (.), curry, uncurry
@@ -19,6 +20,7 @@ import Data.Functor.Product as F
1920
import Data.Functor.Sum as F
2021
import Data.List.NonEmpty
2122
import Data.Proxy
23+
import qualified Test.QuickCheck as QC
2224

2325
import Category
2426

@@ -136,3 +138,14 @@ instance Functor ZipList where
136138
type Cod ZipList = Cod []
137139
proveCod = Sub Dict
138140
fmap f (ZipList xs) = ZipList (fmap f xs)
141+
142+
143+
144+
newtype NList a = NList [a]
145+
deriving (Eq, Ord, Read, Show, QC.Arbitrary, QC.Arbitrary1)
146+
147+
instance Functor NList where
148+
type Dom NList = (-#>)
149+
type Cod NList = (->)
150+
proveCod = Sub Dict
151+
fmap f (NList xs) = NList (fmap (apply f) xs)

Diff for: ‎lib/Unfoldable.hs

+44-28
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import Functor
2121
-- | Unfoldable
2222
-- (this uses the State monad)
2323
class Functor f => Unfoldable f where
24-
-- {-# MINIMAL mapUnfold | unfoldr #-}
25-
unfold :: (k ~ Dom f, Obj k a, Comonoid a) => a -> (a, f a)
24+
{-# MINIMAL unfoldr, fromList #-}
25+
unfold :: (k ~ Dom f, Obj k a, Comonoid a) => a -> (f a, a)
2626
unfold = mapUnfold id
27-
mapUnfold :: (k ~ Dom f, Obj k b, Comonoid a) => (a -> b) -> a -> (a, f b)
27+
mapUnfold :: (k ~ Dom f, Obj k b, Comonoid a) => (a -> b) -> a -> (f b, a)
2828
mapUnfold f = unfoldr counit (\y -> let (y1, y2) = split y in (f y1, y2))
2929
unfoldr :: (k ~ Dom f, Obj k b)
30-
=> (a -> Bool) -> (a -> (b, a)) -> a -> (a, f b)
30+
=> (a -> Bool) -> (a -> (b, a)) -> a -> (f b, a)
3131
-- unfoldr c s x = getCoendo ... Coendo ...
3232
fromList :: (k ~ Dom f, Obj k a, Obj (Dom []) a) => [a] -> Maybe (f a)
3333
-- TODO: This is broken since head is partial
@@ -36,51 +36,67 @@ class Functor f => Unfoldable f where
3636

3737

3838
instance Unfoldable Proxy where
39-
mapUnfold _ x = (x, Proxy)
40-
unfoldr _ _ x = (x, Proxy)
41-
fromList _ = Just Proxy
39+
unfoldr _ _ x = (Proxy, x)
40+
fromList [] = Just Proxy
41+
fromList _ = Nothing
4242

4343
instance Unfoldable Identity where
44-
mapUnfold f x = let (x1, x2) = split x in (x2, Identity (f x1))
45-
unfoldr c s x = let (y, x') = s x in (x', Identity y)
44+
unfoldr c s x = let (y, x') = s x in (Identity y, x')
45+
fromList [x] = Just (Identity x)
46+
fromList _ = Nothing
4647

4748
instance Monoid a => Unfoldable (Either a) where
48-
mapUnfold f x = if counit x
49-
then (x, Left mempty)
50-
else let (x1, x2) = split x in (x2, Right (f x1))
49+
unfoldr c s x = if c x
50+
then (Left mempty, x)
51+
else let (y, x') = s x in (Right y, x')
52+
fromList [] = Just (Left mempty)
53+
fromList [x] = Just (Right x)
54+
fromList _ = Nothing
5155

5256
instance Monoid a => Unfoldable ((,) a) where
53-
mapUnfold f x = let (x1, x2) = split x in (x2, (mempty, f x1))
57+
unfoldr c s x = let (y, x') = s x in ((mempty, y), x')
58+
fromList [x] = Just (mempty, x)
59+
fromList _ = Nothing
5460

5561
instance ( Unfoldable f, Unfoldable g
5662
, Dom f ~ Dom g, Cod f ~ Cod g, Cod g ~ (->)
5763
) => Unfoldable (F.Product f g) where
58-
mapUnfold f x = let (y, xs) = mapUnfold f x
59-
(z, ys) = mapUnfold f y
60-
in (z, Pair xs ys)
64+
unfoldr c s x = let (xs, x') = unfoldr c s x
65+
(ys, x'') = unfoldr c s x'
66+
in (Pair xs ys, x'')
6167

6268
-- instance ( Unfoldable f, Unfoldable g
6369
-- , Dom f ~ Dom g, Cod f ~ Cod g, Cod g ~ (->)
6470
-- ) => Unfoldable (F.Compose f g) where
6571

6672
instance Monoid a => Unfoldable (Const a) where
67-
mapUnfold _ x = (x, Const mempty)
73+
unfoldr _ _ x = (Const mempty, x)
74+
fromList [] = Just (Const mempty)
75+
fromList _ = Nothing
6876

6977
instance Unfoldable Maybe where
70-
mapUnfold f x = if counit x
71-
then (x, Nothing)
72-
else let (x1, x2) = split x in (x2, Just (f x1))
78+
unfoldr c s x = if c x
79+
then (Nothing, x)
80+
else let (y, x') = s x in (Just y, x')
81+
fromList [] = Just Nothing
82+
fromList [x] = Just (Just x)
83+
fromList _ = Nothing
7384

7485
instance Unfoldable [] where
75-
mapUnfold f x = if counit x
76-
then (x, [])
77-
else let (x1, x2) = split x
78-
in fmap (f x1 :) (mapUnfold f x2)
86+
unfoldr c s x = if c x
87+
then ([], x)
88+
else let (y, x') = s x
89+
(ys, x'') = unfoldr c s x'
90+
in (y : ys, x'')
91+
fromList = Just
7992

8093
instance Unfoldable NonEmpty where
81-
mapUnfold f x = let (x1, x') = split x
82-
(x'', y2) = mapUnfold f x'
83-
in (x'', f x1 :| y2)
94+
unfoldr c s x = let (y, x') = s x
95+
(ys, x'') = unfoldr c s x'
96+
in (y :| ys, x'')
97+
fromList (x : xs) = Just (x :| xs)
98+
fromList _ = Nothing
8499

85100
instance Unfoldable ZipList where
86-
mapUnfold f x = fmap ZipList (mapUnfold f x)
101+
unfoldr c s x = let (y, x') = unfoldr c s x in (ZipList y, x')
102+
fromList = Just . ZipList

Diff for: ‎package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ default-extensions:
7171

7272
library:
7373
dependencies:
74-
# - QuickCheck
74+
- QuickCheck
7575
- base
7676
# - bifunctors
7777
- constraints

Diff for: ‎test/ApplicativeSpec.hs

+103
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,26 @@ prop_List_Applicative_inter fs' x =
307307
let fs = applyFun <$> fs'
308308
in uncurry (===) (getEqual (law_Applicative_inter fs x))
309309

310+
prop_List_Applicative_id' :: Fun NA NB -> [NA] -> Property
311+
prop_List_Applicative_id' (Fn f) xs =
312+
uncurry (===) (getEqual (law_Applicative_id' f xs))
313+
314+
prop_List_Applicative_id_left' :: Fun (NA, NB) NC -> NA -> [NB] -> Property
315+
prop_List_Applicative_id_left' (Fn f) x ys =
316+
uncurry (===) (getEqual (law_Applicative_id_left' f x ys))
317+
318+
prop_List_Applicative_id_right' ::
319+
Fun (NA, NB) NC -> [NA] -> NB -> Property
320+
prop_List_Applicative_id_right' (Fn f) xs y =
321+
uncurry (===) (getEqual (law_Applicative_id_right' f xs y))
322+
323+
prop_List_Applicative_assoc' ::
324+
Fun NA NA -> Fun NB NB -> Fun NC NC -> Fun (NA, (NB, NC)) NA ->
325+
Small1 [NA] -> Small1 [NB] -> Small1 [NC] -> Property
326+
prop_List_Applicative_assoc'
327+
(Fn f) (Fn g) (Fn h) (Fn i) (Small1 xs) (Small1 ys) (Small1 zs) =
328+
uncurry (===) (getEqual (law_Applicative_assoc' f g h i xs ys zs))
329+
310330

311331

312332
prop_NonEmpty_Applicative_id :: NonEmpty A -> Property
@@ -330,6 +350,28 @@ prop_NonEmpty_Applicative_inter fs' x =
330350
let fs = applyFun <$> fs'
331351
in uncurry (===) (getEqual (law_Applicative_inter fs x))
332352

353+
prop_NonEmpty_Applicative_id' :: Fun NA NB -> NonEmpty NA -> Property
354+
prop_NonEmpty_Applicative_id' (Fn f) xs =
355+
uncurry (===) (getEqual (law_Applicative_id' f xs))
356+
357+
prop_NonEmpty_Applicative_id_left' ::
358+
Fun (NA, NB) NC -> NA -> NonEmpty NB -> Property
359+
prop_NonEmpty_Applicative_id_left' (Fn f) x ys =
360+
uncurry (===) (getEqual (law_Applicative_id_left' f x ys))
361+
362+
prop_NonEmpty_Applicative_id_right' ::
363+
Fun (NA, NB) NC -> NonEmpty NA -> NB -> Property
364+
prop_NonEmpty_Applicative_id_right' (Fn f) xs y =
365+
uncurry (===) (getEqual (law_Applicative_id_right' f xs y))
366+
367+
prop_NonEmpty_Applicative_assoc' ::
368+
Fun NA NA -> Fun NB NB -> Fun NC NC -> Fun (NA, (NB, NC)) NA ->
369+
Small1 (NonEmpty NA) -> Small1 (NonEmpty NB) -> Small1 (NonEmpty NC) ->
370+
Property
371+
prop_NonEmpty_Applicative_assoc'
372+
(Fn f) (Fn g) (Fn h) (Fn i) (Small1 xs) (Small1 ys) (Small1 zs) =
373+
uncurry (===) (getEqual (law_Applicative_assoc' f g h i xs ys zs))
374+
333375

334376

335377
prop_ZipList_Applicative_id :: ZipList A -> Property
@@ -354,3 +396,64 @@ prop_ZipList_Applicative_inter fs' x =
354396
let fs = applyFun <$> fs'
355397
(ZipList us, ZipList vs) = getEqual (law_Applicative_inter fs x)
356398
in take 100 us === take 100 vs
399+
400+
prop_ZipList_Applicative_id' :: Fun NA NB -> ZipList NA -> Property
401+
prop_ZipList_Applicative_id' (Fn f) xs =
402+
uncurry (===) (getEqual (law_Applicative_id' f xs))
403+
404+
prop_ZipList_Applicative_id_left' ::
405+
Fun (NA, NB) NC -> NA -> ZipList NB -> Property
406+
prop_ZipList_Applicative_id_left' (Fn f) x ys =
407+
uncurry (===) (getEqual (law_Applicative_id_left' f x ys))
408+
409+
prop_ZipList_Applicative_id_right' ::
410+
Fun (NA, NB) NC -> ZipList NA -> NB -> Property
411+
prop_ZipList_Applicative_id_right' (Fn f) xs y =
412+
uncurry (===) (getEqual (law_Applicative_id_right' f xs y))
413+
414+
prop_ZipList_Applicative_assoc' ::
415+
Fun NA NA -> Fun NB NB -> Fun NC NC -> Fun (NA, (NB, NC)) NA ->
416+
Small1 (ZipList NA) -> Small1 (ZipList NB) -> Small1 (ZipList NC) ->
417+
Property
418+
prop_ZipList_Applicative_assoc'
419+
(Fn f) (Fn g) (Fn h) (Fn i) (Small1 xs) (Small1 ys) (Small1 zs) =
420+
uncurry (===) (getEqual (law_Applicative_assoc' f g h i xs ys zs))
421+
422+
423+
424+
newtype NA = NA Integer
425+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
426+
instance Function NA where
427+
function = functionMap (\(NA x) -> x) NA
428+
newtype NB = NB Integer
429+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
430+
instance Function NB where
431+
function = functionMap (\(NB x) -> x) NB
432+
newtype NC = NC Integer
433+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
434+
instance Function NC where
435+
function = functionMap (\(NC x) -> x) NC
436+
437+
438+
439+
prop_NList_Applicative_id' :: Fun NA NB -> NList NA -> Property
440+
prop_NList_Applicative_id' (Fn f) xs =
441+
uncurry (===) (getEqual (law_Applicative_id' (NFun f) xs))
442+
443+
prop_NList_Applicative_id_left' ::
444+
Fun (NA *#* NB) NC -> NA -> NList NB -> Property
445+
prop_NList_Applicative_id_left' (Fn f) x ys =
446+
uncurry (===) (getEqual (law_Applicative_id_left' (NFun f) x ys))
447+
448+
prop_NList_Applicative_id_right' ::
449+
Fun (NA *#* NB) NC -> NList NA -> NB -> Property
450+
prop_NList_Applicative_id_right' (Fn f) xs y =
451+
uncurry (===) (getEqual (law_Applicative_id_right' (NFun f) xs y))
452+
453+
prop_NList_Applicative_assoc' ::
454+
Fun NA NA -> Fun NB NB -> Fun NC NC -> Fun (NA *#* (NB *#* NC)) NA ->
455+
Small1 (NList NA) -> Small1 (NList NB) -> Small1 (NList NC) -> Property
456+
prop_NList_Applicative_assoc'
457+
(Fn f) (Fn g) (Fn h) (Fn i) (Small1 xs) (Small1 ys) (Small1 zs) =
458+
uncurry (===) (getEqual (law_Applicative_assoc'
459+
(NFun f) (NFun g) (NFun h) (NFun i) xs ys zs))

Diff for: ‎test/CategorySpec.hs

+31
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,34 @@ prop_Hask_Category_comp_id_right (Fn f) x =
2323
prop_Hask_Category_comp_assoc :: Fun A C -> Fun B A -> Fun A B -> A -> Property
2424
prop_Hask_Category_comp_assoc (Fn h) (Fn g) (Fn f) x =
2525
uncurry (===) (getFnEqual (law_Category_comp_assoc h g f) x)
26+
27+
28+
29+
newtype NA = NA Integer
30+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
31+
instance Function NA where
32+
function = functionMap (\(NA x) -> x) NA
33+
newtype NB = NB Integer
34+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
35+
instance Function NB where
36+
function = functionMap (\(NB x) -> x) NB
37+
newtype NC = NC Integer
38+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
39+
instance Function NC where
40+
function = functionMap (\(NC x) -> x) NC
41+
42+
43+
44+
prop_Num_Category_comp_id_left :: Fun NA NB -> NA -> Property
45+
prop_Num_Category_comp_id_left (Fn f) x =
46+
uncurry (===) (getFnEqual (law_Category_comp_id_left (NFun f)) x)
47+
48+
prop_Num_Category_comp_id_right :: Fun NA NB -> NA -> Property
49+
prop_Num_Category_comp_id_right (Fn f) x =
50+
uncurry (===) (getFnEqual (law_Category_comp_id_right (NFun f)) x)
51+
52+
prop_Num_Category_comp_assoc ::
53+
Fun NA NC -> Fun NB NA -> Fun NA NB -> NA -> Property
54+
prop_Num_Category_comp_assoc (Fn h) (Fn g) (Fn f) x =
55+
uncurry (===) (getFnEqual
56+
(law_Category_comp_assoc (NFun h) (NFun g) (NFun f)) x)

Diff for: ‎test/ComonadSpec.hs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Prelude hiding ( id, (.), curry, uncurry
88
, Functor(..)
99
)
1010
import qualified Prelude
11+
1112
import Data.Constraint
1213
import Data.Functor.Classes
1314
import Data.Functor.Identity
@@ -119,8 +120,9 @@ prop_Sum_Comonad_duplicate :: Sum FB FA A -> Property
119120
prop_Sum_Comonad_duplicate xs =
120121
uncurry (===) (getFnEqual law_Comonad_duplicate xs)
121122

122-
prop_Sum_Comonad_extend :: Fun (Sum FB FA A) B -> Sum FB FA A -> Property
123-
prop_Sum_Comonad_extend (Fn f) xs =
123+
prop_Sum_Comonad_extend ::
124+
Fun (Sum FB FA A) B -> Small1 (Sum FB FA A) -> Property
125+
prop_Sum_Comonad_extend (Fn f) (Small1 xs) =
124126
uncurry (===) (getFnEqual (law_Comonad_extend f) xs)
125127

126128

@@ -134,8 +136,8 @@ prop_Product_Comonad_duplicate xs =
134136
uncurry (===) (getFnEqual law_Comonad_duplicate xs)
135137

136138
prop_Product_Comonad_extend ::
137-
Fun (Product FB FA A) B -> Product FB FA A -> Property
138-
prop_Product_Comonad_extend (Fn f) xs =
139+
Fun (Product FB FA A) B -> Small1 (Product FB FA A) -> Property
140+
prop_Product_Comonad_extend (Fn f) (Small1 xs) =
139141
uncurry (===) (getFnEqual (law_Comonad_extend f) xs)
140142

141143

Diff for: ‎test/FunctorSpec.hs

+25
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,28 @@ prop_ZipList_Functor_id xs =
183183
prop_ZipList_Functor_assoc :: Fun B C -> Fun A B -> ZipList A -> Property
184184
prop_ZipList_Functor_assoc (Fn g) (Fn f) xs =
185185
uncurry (===) (getFnEqual (law_Functor_assoc g f) xs)
186+
187+
188+
189+
newtype NA = NA Integer
190+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
191+
instance Function NA where
192+
function = functionMap (\(NA x) -> x) NA
193+
newtype NB = NB Integer
194+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
195+
instance Function NB where
196+
function = functionMap (\(NB x) -> x) NB
197+
newtype NC = NC Integer
198+
deriving (Eq, Ord, Read, Show, Num, Arbitrary, CoArbitrary)
199+
instance Function NC where
200+
function = functionMap (\(NC x) -> x) NC
201+
202+
203+
204+
prop_NList_Functor_id :: NList NA -> Property
205+
prop_NList_Functor_id xs =
206+
uncurry (===) (getFnEqual law_Functor_id xs)
207+
208+
prop_NList_Functor_assoc :: Fun NB NC -> Fun NA NB -> NList NA -> Property
209+
prop_NList_Functor_assoc (Fn g) (Fn f) xs =
210+
uncurry (===) (getFnEqual (law_Functor_assoc (NFun g) (NFun f)) xs)

0 commit comments

Comments
 (0)
Please sign in to comment.