[Haskell-cafe] Is there a nicer way to do this?
Don Stewart
dons at galois.com
Sun Jul 6 19:55:27 EDT 2008
mfeathers:
>
>
> segment :: Int -> [a] -> [[a]]
> segment 0 _ = []
> segment _ [] = []
> segment n x = (take n x) : segment n (drop n x)
The first set of parens can go,
segment n x = take n x : segment n (drop n x)
>
> I did a version of this which used splitAt but I wasn't sure whether it
> was going to buy me anything re performance that would justify its ugliness.
Besides,
splitAt n xs = (take n xs, drop n xs)
-- Don
More information about the Haskell-Cafe
mailing list