
On Fri, Sep 17, 2010 at 10:48 AM, Christian Maeder
Am 16.09.2010 16:39, schrieb Daniel Fischer:
The proposed implementation,
intersperse :: a -> [a] -> [a] intersperse _ [] = [] intersperse sep (x:xs) = x : go xs where go [] = [] go (y:ys) = sep : y : go ys ... Therefore I proposed the following implementation:
intersperse :: a -> [a] -> [a] intersperse s l = case l of [] -> l x : r -> x : if null r then r else s : intersperse s r
One additional benefit about the original proposed implementation is that it applies the static argument transformation: the 'sep' argument is brought into scope of the worker function 'go' which then doesn't need to pass it to each recursion as in the original implementation. It would be interesting to see if this provides a noticeable performance benefit. Criterion anyone? Bas