I'm trying to do a wrapper newtype for my Ap ZipList
based on the advice given at Haskell quickBatch testing: Applicative Monoid ZipList. My version of GHC is 8.8.4 and I compile using stack. My full code:
newtype Ap f a = Ap { getAp :: f a }
deriving (Eq, Show)
instance (Applicative f, Semigroup a) =>
Semigroup (Ap f a) where
Ap xs <> Ap ys =
Ap $ liftA2 (<>) xs ys
instance (Applicative f, Monoid a) =>
Monoid (Ap f a) where
mempty = Ap $ pure mempty
Ap xs `mappend` Ap ys =
Ap $ liftA2 mappend xs ys
app :: Ap ZipList (Sum Int)
app = Ap (ZipList [1,2 :: Sum Int])
test :: Ap ZipList (Sum Int)
test = app <> app
instance Arbitrary (f a) =>
Arbitrary (Ap f a) where
arbitrary = Ap <$> arbitrary
instance Eq a => EqProp (Ap ZipList a) where
xs =-= ys = xs' `eq` ys' where
xs' =
let (Ap (ZipList l)) = xs
in take 3000 l
ys' =
let l = (getZipList . getAp) ys
in take 3000 l
newtype MonZipList a =
MonZipList (Ap ZipList a)
deriving (Semigroup, Monoid, Eq, Show)
deriving instance Functor f =>
Functor (Ap f)
deriving instance Applicative f =>
Applicative (Ap f)
monapp :: MonZipList (Sum Int)
monapp = MonZipList app
instance Arbitrary a =>
Arbitrary (MonZipList a) where
arbitrary = MonZipList <$> arbitrary
instance Eq a => EqProp (MonZipList a) where
(=-=) = eq
main :: IO ()
main = do
quickBatch $ monoid app
quickBatch $ monoid monapp
quickBatch $ functor monapp
quickBatch $ applicative monapp
The basic quickBatch $ monoid app
tests run well without problems.
The problems I face are that when I run quickBatch $ monoid monapp
, the monoid tests hangs at the mconcat test and could not be stopped. I had to close my WSL Bash in order to stop it from running.
When I tried quickBatch $ functor monapp
or quickBatch $ applicative monapp
, errors were thrown, thereby making the effectiveness of the wrapper newtype questionable:
Couldn't match type ‘Sum Int’ with ‘(a0, b0, c0)’
Expected type: MonZipList (a0, b0, c0)
Actual type: MonZipList (Sum Int)
In the first argument of ‘functor’, namely ‘monapp’
Are there any solutions to these newtype wrapper problems?