summaryrefslogtreecommitdiff
path: root/Haskell-book/21/instances/src/SkiFree.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-12-11 10:28:11 +0100
committerEugen Wissner <belka@caraus.de>2025-12-11 10:28:11 +0100
commit98329e0a3dd4f78b5d815ac3896272ec70904901 (patch)
tree80f9c56cfe2ac20232358f236d32e84bd683be1b /Haskell-book/21/instances/src/SkiFree.hs
parent3624c712d72d246f21d4e710cec7c11e052e0326 (diff)
downloadbook-exercises-98329e0a3dd4f78b5d815ac3896272ec70904901.tar.gz
Add remaining haskell book exercises
Diffstat (limited to 'Haskell-book/21/instances/src/SkiFree.hs')
-rw-r--r--Haskell-book/21/instances/src/SkiFree.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/Haskell-book/21/instances/src/SkiFree.hs b/Haskell-book/21/instances/src/SkiFree.hs
new file mode 100644
index 0000000..70e87dc
--- /dev/null
+++ b/Haskell-book/21/instances/src/SkiFree.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE FlexibleContexts #-}
+
+module SkiFree where
+
+import Test.QuickCheck
+import Test.QuickCheck.Checkers
+
+data S n a = S (n a) a deriving (Eq, Show)
+
+instance ( Functor n
+ , Arbitrary (n a)
+ , Arbitrary a)
+ => Arbitrary (S n a) where
+ arbitrary = S <$> arbitrary <*> arbitrary
+
+--instance ( Applicative n
+-- , Testable (n Property)
+-- , EqProp a)
+-- => EqProp (S n a) where
+-- (S x y) =-= (S p q) =
+-- (property $ (=-=) <$> x <*> p) .&. (y =-= q)
+instance (Eq (n a), Eq a) => EqProp (S n a) where
+ (=-=) = eq
+
+instance Functor n => Functor (S n) where
+ fmap f (S x y) = S (fmap f x) (f y)
+
+instance Foldable n => Foldable (S n) where
+ foldMap f (S n a) = mappend (foldMap f n) (f a)
+
+instance Traversable n => Traversable (S n) where
+ traverse f (S x y) = S <$> (traverse f x) <*> (f y)