diff --git a/Haskell Excercises & Code/Chapter25 - Composing Types/EitherTT.hs b/Haskell Excercises & Code/Chapter25 - Composing Types/EitherTT.hs index 223a4d0..3ee1999 100644 --- a/Haskell Excercises & Code/Chapter25 - Composing Types/EitherTT.hs +++ b/Haskell Excercises & Code/Chapter25 - Composing Types/EitherTT.hs @@ -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 @@ -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 \ No newline at end of file diff --git a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/config b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/config index 3166efb..93bdbaf 100644 Binary files a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/config and b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/config differ diff --git a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/elaborated-plan b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/elaborated-plan index 246e3d7..897da58 100644 Binary files a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/elaborated-plan and b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/elaborated-plan differ diff --git a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/improved-plan b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/improved-plan index 44f6a7a..2e356d9 100644 Binary files a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/improved-plan and b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/improved-plan differ diff --git a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/solver-plan b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/solver-plan index d1b8e80..5077406 100644 Binary files a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/solver-plan and b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/solver-plan differ diff --git a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/up-to-date b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/up-to-date index 9a794ba..b38e395 100644 Binary files a/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/up-to-date and b/Haskell Excercises & Code/Chapter25 - Composing Types/dist-newstyle/cache/up-to-date differ