unwrap1 :: [[a]] -> [a]
unwrap1 [] = []
unwrap1 (xs:xss) = xs ++ unwrap1 xss
unwrap1 [[10,20],[30,40,50],[60]]
-- "pumping" version or "tail-recursive" version
unwrap2 :: [[a]] -> [a]
unwrap2 xss = unwrapHelper xss []
unwrapHelper :: [[a]] -> [a] -> [a]
unwrapHelper [] result = result
unwrapHelper (xs:xss) result = unwrapHelper xss (result ++ xs)
unwrap2 [[10,20],[30,40,50],[60]]
reverse1 :: [a] -> [a]
reverse1 [] = []
reverse1 (x:xs) = reverse1 xs ++ [x]
reverse1 [1,2,3]
reverse2 :: [a] -> [a]
reverse2 xs = reverseHelper xs []
reverseHelper [] result = result
reverseHelper (x:xs) result = reverseHelper xs (x:result)
reverse2 [1,2,3]
smallest1 :: [String] -> String
smallest1 [s] = s
smallest1 (s:ss) = min s (smallest1 ss)
smallest1 ["tom","john","alice"]
smallest2 :: [String] -> String
smallest2 ss = smallestHelper ss (head ss)
smallestHelper :: [String] -> String -> String
smallestHelper [] result = result
smallestHelper (s:ss) result
| s < result = smallestHelper ss s
| otherwise = smallestHelper ss result
smallest2 ["tom","john","alice"]
-- split in mergesort
split1 :: Ord a => [a] -> ([a],[a])
split1 [] = ([],[])
split1 (x:xs)
| null xs = ([x],[])
| otherwise = (x:list1,head xs:list2)
where (list1,list2) = split1 (tail xs)
split1 [1,2,3,4,5,6,7,8,9]