Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# Language InstanceSigs #-}
- import Data.Monoid
- import Test.QuickCheck
- import Test.QuickCheck.Checkers
- import Test.QuickCheck.Classes
- newtype ZipList' a = ZipList' [a]
- deriving (Eq, Show)
- instance Eq a => EqProp (ZipList' a) where
- xs =-= ys = xs' `eq` ys' where
- xs' = let (ZipList' l) = xs
- in take 3000 l
- ys' = let (ZipList' l) = ys
- in take 3000 l
- instance Semigroup (ZipList' a) where
- (<>) :: ZipList' a -> ZipList' a -> ZipList' a
- (<>) (ZipList' x) (ZipList' y) = ZipList' $ x <> y
- instance Monoid (ZipList' a) where
- mempty :: ZipList' a
- mempty = ZipList' []
- instance Functor ZipList' where
- fmap :: (a -> b) -> ZipList' a -> ZipList' b
- fmap f (ZipList' x) = ZipList' $ f <$> x
- instance Applicative ZipList' where
- pure :: a -> ZipList' a
- pure x = ZipList' [x]
- (<*>) :: ZipList' (a -> b) -> ZipList' a -> ZipList' b
- (<*>) (ZipList' []) _ = mempty
- (<*>) (ZipList' [f]) x = f <$> x
- (<*>) (ZipList' (f:fs)) (ZipList' (x:xs)) = pure (f x) <> ((ZipList' fs) <*> (ZipList' xs))
- instance (Arbitrary a) => Arbitrary (ZipList' a) where
- arbitrary :: Gen (ZipList' a)
- arbitrary = ZipList' <$> arbitrary
- main :: IO ()
- main = do
- quickBatch $ monoid (undefined :: ZipList' (Int, String, Int))
- quickBatch $ applicative (undefined :: ZipList' (Int, String, Int))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement