Skip to content

Commit

Permalink
Remove Monad constraints where they are implied by other constraints
Browse files Browse the repository at this point in the history
As suggested by illissius@reddit
  • Loading branch information
UnkindPartition committed Feb 20, 2013
1 parent d523a94 commit 3e087aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Test/SmallCheck/Property.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ makeAtomic (Property prop) =
--
-- 'over' does not affect the quantification context.
over
:: (Monad m, Show a, Testable m b)
:: (Show a, Testable m b)
=> Series m a -> (a -> b) -> Property m
over = testFunction

Expand Down Expand Up @@ -153,7 +153,7 @@ instance (Monad m, m ~ n) => Testable n (Property m) where
test = id

testFunction
:: (Monad m, Show a, Testable m b)
:: (Show a, Testable m b)
=> Series m a -> (a -> b) -> Property m
testFunction s f = Property $ reader $ \env ->
let
Expand Down
28 changes: 14 additions & 14 deletions Test/SmallCheck/Series.hs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ cons4 f = decDepth $
alts0 :: Series m a -> Series m a
alts0 s = s

alts1 :: (Monad m, CoSerial m a) => Series m b -> Series m (a->b)
alts1 :: CoSerial m a => Series m b -> Series m (a->b)
alts1 rs =
decDepthChecked (constM rs) (coseries rs)

Expand All @@ -333,7 +333,7 @@ alts4 rs =
(coseries $ coseries $ coseries $ coseries rs)

-- | Same as 'alts1', but preserves the depth.
newtypeAlts :: (Monad m, CoSerial m a) => Series m b -> Series m (a->b)
newtypeAlts :: CoSerial m a => Series m b -> Series m (a->b)
newtypeAlts = coseries

-- }}}
Expand Down Expand Up @@ -465,19 +465,19 @@ instance Monad m => CoSerial m Char where
coseries rs >>- \f ->
return $ \c -> f (N (fromEnum c - fromEnum 'a'))

instance (Monad m, Serial m a, Serial m b) => Serial m (a,b) where
instance (Serial m a, Serial m b) => Serial m (a,b) where
series = cons2 (,)
instance (Monad m, CoSerial m a, CoSerial m b) => CoSerial m (a,b) where
instance (CoSerial m a, CoSerial m b) => CoSerial m (a,b) where
coseries rs = uncurry <$> alts2 rs

instance (Monad m, Serial m a, Serial m b, Serial m c) => Serial m (a,b,c) where
instance (Serial m a, Serial m b, Serial m c) => Serial m (a,b,c) where
series = cons3 (,,)
instance (Monad m, CoSerial m a, CoSerial m b, CoSerial m c) => CoSerial m (a,b,c) where
instance (CoSerial m a, CoSerial m b, CoSerial m c) => CoSerial m (a,b,c) where
coseries rs = uncurry3 <$> alts3 rs

instance (Monad m, Serial m a, Serial m b, Serial m c, Serial m d) => Serial m (a,b,c,d) where
instance (Serial m a, Serial m b, Serial m c, Serial m d) => Serial m (a,b,c,d) where
series = cons4 (,,,)
instance (Monad m, CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => CoSerial m (a,b,c,d) where
instance (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => CoSerial m (a,b,c,d) where
coseries rs = uncurry4 <$> alts4 rs

instance Monad m => Serial m Bool where
Expand All @@ -488,15 +488,15 @@ instance Monad m => CoSerial m Bool where
rs >>- \r2 ->
return $ \x -> if x then r1 else r2

instance (Monad m, Serial m a) => Serial m (Maybe a) where
instance (Serial m a) => Serial m (Maybe a) where
series = cons0 Nothing \/ cons1 Just
instance (Monad m, CoSerial m a) => CoSerial m (Maybe a) where
instance (CoSerial m a) => CoSerial m (Maybe a) where
coseries rs =
maybe <$> alts0 rs <~> alts1 rs

instance (Monad m, Serial m a, Serial m b) => Serial m (Either a b) where
instance (Serial m a, Serial m b) => Serial m (Either a b) where
series = cons1 Left \/ cons1 Right
instance (Monad m, CoSerial m a, CoSerial m b) => CoSerial m (Either a b) where
instance (CoSerial m a, CoSerial m b) => CoSerial m (Either a b) where
coseries rs =
either <$> alts1 rs <~> alts1 rs

Expand All @@ -508,11 +508,11 @@ instance CoSerial m a => CoSerial m [a] where
alts2 rs >>- \f ->
return $ \xs -> case xs of [] -> y; x:xs' -> f x xs'

instance (CoSerial m a, Serial m b, Monad m) => Serial m (a->b) where
instance (CoSerial m a, Serial m b) => Serial m (a->b) where
series = coseries series
-- Thanks to Ralf Hinze for the definition of coseries
-- using the nest auxiliary.
instance (Serial m a, CoSerial m a, Serial m b, CoSerial m b, Monad m) => CoSerial m (a->b) where
instance (Serial m a, CoSerial m a, Serial m b, CoSerial m b) => CoSerial m (a->b) where
coseries r = do
args <- unwind series

Expand Down

0 comments on commit 3e087aa

Please sign in to comment.