diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-12-11 10:28:11 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-12-11 10:28:11 +0100 |
| commit | 98329e0a3dd4f78b5d815ac3896272ec70904901 (patch) | |
| tree | 80f9c56cfe2ac20232358f236d32e84bd683be1b /Haskell-book/16/func/test/Spec.hs | |
| parent | 3624c712d72d246f21d4e710cec7c11e052e0326 (diff) | |
| download | book-exercises-98329e0a3dd4f78b5d815ac3896272ec70904901.tar.gz | |
Add remaining haskell book exercises
Diffstat (limited to 'Haskell-book/16/func/test/Spec.hs')
| -rw-r--r-- | Haskell-book/16/func/test/Spec.hs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Haskell-book/16/func/test/Spec.hs b/Haskell-book/16/func/test/Spec.hs new file mode 100644 index 0000000..14de325 --- /dev/null +++ b/Haskell-book/16/func/test/Spec.hs @@ -0,0 +1,54 @@ +{-# LANGUAGE ViewPatterns #-} + +import Func +import Test.QuickCheck +import Test.QuickCheck.Function + +functorIdentity :: (Functor f, Eq (f a)) => f a -> Bool +functorIdentity f = fmap id f == f + +functorCompose :: (Eq (f c), Functor f) => + (a -> b) + -> (b -> c) + -> f a + -> Bool +functorCompose f g x = + (fmap g (fmap f x)) == (fmap (g . f) x) + +functorCompose' :: (Eq (f c), Functor f) => + f a + -> Fun a b + -> Fun b c + -> Bool +functorCompose' x (Fun _ f) (Fun _ g) = + (fmap (g . f) x) == (fmap g . fmap f $ x) + +main :: IO () +main = do + quickCheck (functorIdentity :: Identity Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Identity Int -> Bool) + quickCheck (functorCompose' :: Identity Int -> Fun Int Int -> Fun Int Int -> Bool) + + quickCheck (functorIdentity :: Pair Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Pair Int -> Bool) + quickCheck (functorCompose' :: Pair Int -> Fun Int Int -> Fun Int Int -> Bool) + + quickCheck (functorIdentity :: Two Int Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Two Int Int -> Bool) + quickCheck (functorCompose' :: Two Int Int -> Fun Int Int -> Fun Int Int -> Bool) + + quickCheck (functorIdentity :: Three Int Int Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Three Int Int Int -> Bool) + quickCheck (functorCompose' :: Three Int Int Int -> Fun Int Int -> Fun Int Int -> Bool) + + quickCheck (functorIdentity :: Three' Int Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Three' Int Int -> Bool) + quickCheck (functorCompose' :: Three' Int Int -> Fun Int Int -> Fun Int Int -> Bool) + + quickCheck (functorIdentity :: Four Int Int Int Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Four Int Int Int Int -> Bool) + quickCheck (functorCompose' :: Four Int Int Int Int -> Fun Int Int -> Fun Int Int -> Bool) + + quickCheck (functorIdentity :: Four' Int Int -> Bool) + quickCheck ((functorCompose (+1) (*2)) :: Four' Int Int -> Bool) + quickCheck (functorCompose' :: Four' Int Int -> Fun Int Int -> Fun Int Int -> Bool) |
