Merge Sort

-- Performs merge sort on a list whose elements are sortable

mergesort :: Ord a => [a] -> [a]
mergesort n 
       | (length n < 2) = n
       | otherwise = merge (mergesort left) (mergesort right)
         where 
           left = take (length n `div` 2) n
           right = drop (length n `div` 2) n
           merge ls rs
              | (ls == [] && rs == []) = []
              | (ls == []) = rs
              | (rs == []) = ls
              | (ls <= rs) = (ls !! 0) : (merge (drop 1 ls) rs)
              | otherwise = (rs !! 0) : (merge ls (drop 1 rs))