From 98329e0a3dd4f78b5d815ac3896272ec70904901 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 11 Dec 2025 10:28:11 +0100 Subject: Add remaining haskell book exercises --- Haskell-book/21/instances/src/SkiFree.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Haskell-book/21/instances/src/SkiFree.hs (limited to 'Haskell-book/21/instances/src/SkiFree.hs') 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) -- cgit v1.2.3