{- Setup -} type Nat = Maybe Int {- Task 1 -} nat :: Int -> Nat nat _ = undefined {- Task 2 -} consEither :: a -> Either e [a] -> Either e [a] consEither _ _ = undefined {- Task 3 -} limit :: Nat -> [a] -> Either Nat [a] limit _ _ = undefined {- Task 4 -} skip :: Nat -> [a] -> Either Nat [a] skip _ _ = undefined {- Task 5 -} split :: Int -> [a] -> Either Int [[a]] split _ _ = undefined {- Tests -} tests = do -- nat check "nat1" "Just 10" (nat 10) check "nat2" "Nothing" (nat (-1)) -- consEither check "consEither1" "Right [1,2,3,4,5]" (consEither 1 (Right [2..5]) :: Either Int [Int]) check "consEither2" "Left True" (consEither 1 (Left True) :: Either Bool [Int]) -- limit check "limit1" "Right [1,2]" (limit (nat 2) [1,2,3]) check "limit2" "Right \"hell\"" (limit (nat 4) "hello") check "limit3" "True" (isLeft (limit (nat 10) "hello")) -- skip check "skip1" "Right [3]" (skip (nat 2) [1,2,3]) check "skip2" "Right \"o\"" (skip (nat 4) "hello") check "skip3" "True" (isLeft (skip (nat 10) [True])) -- split check "split1" "Right [[]]" (split 0 ([] :: [Int])) check "split2" "Left 1" (split 1 ([] :: [Int])) check "split3" "Left 0" (split 0 [1..4]) check "split4" "Right [[1],[2],[3],[4]]" (split 1 [1..4]) check "split5" "Right [[1,2],[3,4]]" (split 2 [1..4]) check "split6" "Left 3" (split 3 [1..4]) check "split7" "Right [[1,2,3,4]]" (split 4 [1..4]) where isLeft (Left _) = True isLeft _ = False check name e c = do putStr ("*** " ++ name ++ ": ") if show c == e then putStrLn "OK" else putStrLn ("ERROR; expected '" ++ e ++ "', but found '" ++ show c ++ "'")