
#15131: Speed up certain Foldable NonEmpty methods -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Core | Version: 8.2.2 Libraries | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Runtime Unknown/Multiple | performance bug Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Yitzchak Gale pointed out [https://www.reddit.com/r/haskell/comments/8hxpns/why_is_nonempty_missing_som... on Reddit] that some `Foldable` methods are allowed to take default definitions for `NonEmpty` when they probably shouldn't. The biggest problem appears to be `foldr1`, which ends up with a fairly atrocious definition. Yitz seems to think we should also provide a custom definition of `null`, to avoid relying on optimizations, but at present there is no obvious need for that. He doesn't mention this, but the definition of `length` should be changed. Indeed, the default definition of `length` would be better than the custom definition we currently have. I also noticed that we don't mark `foldl1` `INLINE`. At present its unfolding is optimized, so its `foldr` is not exposed. Thus, for example, {{{#!hs foldl1 (+) $ 1 :| [2..n] }}} won't fuse. We can certainly mark `foldl1` `INLINE` to fix this (`INLINABLE` doesn't do the trick), but it would be nice to know if there's another way. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15131 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler