----------------------------------------- --- Example of another Monad: Maybe import Test.QuickCheck mum :: String -> Maybe String mum s = lookup s [("dave","jill"),("jill","jane"),("jane","bob"), ("bob","harry"),("harry", "sally")] -- for example ggrandmum :: String -> Maybe String ggrandmum s = case mum s of Just m -> case (mum m) of Just m' -> mum m' Nothing -> Nothing Nothing -> Nothing -- Now in monadic style {- from the Prelude: instance Monad Maybe where return = Just Nothing >>= f = Nothing (Just x) >>= f = f x -} ggrandmum' :: String -> Maybe String ggrandmum' s = do gm <- mum s ggm <- mum gm mum ggm data Name = Name String deriving Show instance Arbitrary Name where arbitrary = elements $ map Name ["dave", "jill", "jane", "bob"] prop_ggg (Name s) = collect (ggrandmum s) $ ggrandmum' s == ggrandmum s