[Haskell-cafe] Why doesn't GHC use the Hugs definition of splitAt
to avoid traversing the first part of the list twice?
r.kelsall at millstream.com
Fri Apr 25 12:30:09 EDT 2008
I've just been investigating a performance oddity in using splitAt
on a long stream of random numbers. I don't understand why GHC
appears to want to traverse the first part of the list twice.
GHC seems to implement the splitAt function something like
splitAt n xs = (take n xs, drop n xs)
whereas Hugs is something like
splitAt n (x : xs) = (x : xs', xs'')
where (xs', xs'') = splitAt (n-1) xs
which seems much more sensible to me. Wouldn't it be better to change
GHC to the Hugs method? Have I misunderstood something?
More information about the Haskell-Cafe