Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- last' :: [a] -> a
- last' [x] = x
- last' (_:xs) = last xs
- butLast :: [a] -> a
- butLast [x,_] = x
- butLast (_:xs) = butLast xs
- elementAt :: Int -> [a] -> a
- elementAt 0 xs = head xs
- elementAt n (x:xs) = elementAt (n-1) xs
- length' :: [a] -> Int
- length' [] = 0
- length' (x:xs) = 1 + length' xs
- reverse' :: [a] -> [a]
- reverse' [] = []
- reverse' (x:xs) = reverse' xs ++ [x]
- isPalindrome :: Eq a => [a] -> Bool
- isPalindrome [] = True
- isPalindrome [_] = True
- isPalindrome xs
- | last xs == head xs = isPalindrome $ init $ tail xs
- | otherwise = False
- -- No nested list structure in Haskell.
- compress :: Eq a => [a] -> [a]
- compress [] = []
- compress [x] = [x]
- compress (x:xs)
- | x == head xs = compress xs
- | otherwise = x:compress xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement