Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Part a
- and :: [Bool] -> Bool
- and [] = True
- and (False:_) = False
- and (_:xs) = and xs
- -- Part b
- concat :: [[a]] -> [a]
- concat [] = []
- concat (xs:xss) = xs ++ concat xss
- -- Part c
- replicate :: Int -> a -> [a]
- replicate 0 _ = []
- replicate n a = [a] ++ replicate (n - 1) a
- -- Part d
- -- For simplicity, assume that the index is valid
- -- and that the array is non-empty
- (!!) :: [a] -> Int -> a
- (x:xs) !! 0 = x
- (x:xs) !! n = xs !! (n - 1)
- -- Part e
- elem :: Eq a => a -> [a] -> Bool
- elem _ [] = False
- -- Note: ys can be [] which is why (y:ys) matches singletons
- elem x (y:ys)
- | x == y = True
- | x /= y = elem x ys
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement