I have the following function which takes a list and returns two sublists split at a given element n. However, I only need to split it in half, with odd length lists having
You can do it using take and drop:
splitlist :: [a] -> ([a],[a]) splitlist [] = ([],[]) splitlist l = let half = (length(l) +1)`div` 2 in (take half l, drop half l)
or you can take advantage of the function splitAt:
splitlist list = splitAt ((length (list) + 1) `div` 2) list