Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,393
    • Issues 4,393
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 376
    • Merge Requests 376
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18964

Closed
Open
Opened Nov 17, 2020 by Sebastian Graf@sgraf812Developer

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 Nov 17, 2020 by Sebastian Graf
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#18964