Skip to content

Commit

Permalink
Cannot quickcheck to validate laws
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasios Valtinos committed Oct 14, 2022
1 parent 934df9e commit f396ef7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Haskell Excercises & Code/Chapter25 - Composing Types/EitherTT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import Test.QuickCheck

newtype EitherT e m a = EitherT { runEitherT :: m (Either e a) }

newtype TestData a b = TestData b deriving (Eq, Show)
-- -- 1. Write the Functor instance for EitherT:
-- instance Functor m => Functor (EitherT e m) where
-- fmap f (EitherT ema) = EitherT $ (fmap . fmap) f ema


-- Github Arbitrary example
-- instance Arbitrary Cell where
Expand All @@ -16,14 +19,33 @@ newtype TestData a b = TestData b deriving (Eq, Show)
-- Positive y <- arbitrary
-- return $ Cell x y

newtype TestData a b = TestData b deriving (Eq, Show)

instance Functor (TestData a) where
fmap f (TestData b) = TestData (f b)

functorIdentity :: (Functor f, Eq (f a)) => f a -> Bool
functorIdentity f = fmap id f == f


-- arbitrary :: Gen a
genArbit :: (Arbitrary a, Arbitrary b) => Gen (TestData a b)
genArbit = do
x1 <- arbitrary
return $ TestData x1

instance (Arbitrary a, Arbitrary b) => Arbitrary (TestData a b) where
arbitrary = genArbit

randomGen = sample' (genArbit :: Gen (TestData Int Int))

-- 1. Write the Functor instance for EitherT:
instance Functor m => Functor (EitherT e m) where
fmap f (EitherT ema) = EitherT $ (fmap . fmap) f ema
-- validateFunctor :: [TestData Int Int] -> Bool
-- validateFunctor x = return x >>= f
-- where
-- f = fmap id

-- functorIdentity :: (Functor f, Eq (f a)) =>
-- f a
-- -> Bool
-- functorIdentity f =
-- fmap id f == f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit f396ef7

Please sign in to comment.