Data.List.drop should take part in list fusion
Currently, Data.List.drop doesn't take part in list fusion at all. Here's how a fusion-aware definition might look like:
-- | An indexed right fold
ifoldr :: (Int -> a -> b -> b) -> b -> [a] -> b
ifoldr f acc xs = List.foldr c z xs 0
where
c a g = Exts.oneShot (\i -> f i a (g (i+1)))
z = Exts.oneShot $ \_ -> acc
{-# INLINE ifoldr #-}
drp :: Int -> [a] -> [a]
drp !n xs = Exts.build (\c z -> ifoldr (\i a b -> if i < n then b else a `c` b) z xs)
{-# INLINE drp #-}
(Or just inline ifoldr if you fancy that.)
... as in take(FB). Probably we should just mostly copy that implementation, including the tweaks it has received over the years. Maybe it's worthwhile to extract those tweaks into a shared ifoldr impl.
Same for dropWhile.
Edited by Sebastian Graf