
#9742: The default definitions of foldl1 and foldr1 are too strict -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Core Libraries | Version: 7.9 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Easy (less than 1 | Type of failure: Runtime hour) | crash Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- We currently have {{{#!hs foldr1 :: (a -> a -> a) -> t a -> a foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x Nothing = Just x mf x (Just y) = Just (f x y) }}} This has to traverse the entire list before it can do anything. What we want is {{{#!hs mf x r = Just $ case r of Nothing -> x Just y -> f x y }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9742 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler