-- Informatics 1 Functional Programming -- August 2013 import Test.QuickCheck( quickCheck, Arbitrary( arbitrary ), oneof, elements, sized ) import Control.Monad -- defines liftM, liftM2, used below -- Question 1 -- 1a f :: [(Int,Int)] -> [Int] f = undefined -- 1b g :: [(Int,Int)] -> [Int] g = undefined -- Question 2 -- 2a p :: [Int] -> Int p = undefined -- 2b q :: [Int] -> Int q = undefined -- 2c r :: [Int] -> Int r = undefined -- Question 3 data Prop = X | F | T | Not Prop | Prop :<->: Prop deriving (Eq, Ord) -- turns a Prop into a string approximating mathematical notation showProp :: Prop -> String showProp X = "X" showProp F = "F" showProp T = "T" showProp (Not p) = "(~" ++ showProp p ++ ")" showProp (p :<->: q) = "(" ++ showProp p ++ "<->" ++ showProp q ++ ")" -- For QuickCheck instance Show Prop where show = showProp instance Arbitrary Prop where arbitrary = sized prop where prop n | n <= 0 = atom | otherwise = oneof [ atom , liftM Not subform , liftM2 (:<->:) subform subform ] where atom = oneof [elements [X,F,T]] subform = prop (n `div` 2) -- 3a eval :: Prop -> Bool -> Bool eval = undefined -- 3b simplify :: Prop -> Prop simplify = undefined