I need to define group function is Haskell, but i just can do it with takeWhile and dropWhile, but i cant do it with span. And i need to do it with span! Could you help me? Here my code with tW and dW:
group' :: (Eq a) => [a] -> [[a]]
group' [] = []
group' (x:xs) = (x : takeWhile (== x) xs) : group' (dropWhile (== x) xs)
Try this.
group' (x:xs) = a:(group' b) where (a,b) = span (==x) (x:xs)
Span simply returns two lists, which are separated using the given function.