{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE FlexibleContexts #-} import Test.QuickCheck import Control.Monad import Data.List hiding (union, intersect, insert) -- Consider the following data type definition. data Stack a = Stack [a] deriving (Show, Eq) -- We can implement Stack by using list. -- Problem 1 (4 points). Define the following stack operations. emptyStack :: Stack a emptyStack = undefined push :: a -> Stack a -> Stack a push = undefined pop :: Stack a -> (Maybe a, Stack a) pop = undefined size :: Stack a -> Int size = undefined -- Problem 2. (4 points) Think of 4 properties of your stack operations. -- Your implementations must pass quickcheck. prop1 = undefined prop2 = undefined prop3 = undefined prop4 = undefined -- Consider the following data type. data Set a = Set [a] deriving (Show) -- We can implement the following functions on finite sets. -- Problem 3. (2 points) Define the set insertion function. insert :: (Eq a) => a -> Set a -> Set a insert = undefined emptySet :: Set a emptySet = Set [] member :: (Eq a) => a -> Set a -> Bool member x (Set xs) = elem x xs -- Problem 4. (2 points) Define Set a as an instance of Eq class. instance (Eq a) => Eq (Set a) where -- Note that Set [1,2,3] == Set [3, 2,1] should return True. sizeSet :: Set a -> Int sizeSet (Set xs) = length xs -- Problem 5. (2 points) Define the following set union function. union :: (Eq a) => Set a -> Set a -> Set a union = undefined -- Problem 6. (2 points) Define the following set intersection function. intersect :: (Eq a) => Set a -> Set a -> Set a intersect = undefined -- Problem 7. (5 points) Please formulate 5 properties to check the -- implementation of union and intersection. prop5 = undefined prop6 = undefined prop7 = undefined prop8 = undefined prop9 = undefined