Ticket #5756 (closed feature request: wontfix)

Opened 5 months ago

Last modified 4 months ago

Specialize sequence into sequence_ automatically

Reported by: EyalLotem Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Currently, every function that has a useful "effect" as well as a potentially large result value, needs to get two implementations: One that accumulates the result in memory and yields it, and one that avoids accumulating it in the first place.

Some examples:

sequence vs. sequence_

mapM vs. mapM_

Parsec's: many vs. skipMany

Now that I am writing parser combinators, I'm finding that I need a "skip" version of each parser I write, if my parser has a large value.

If GHC can detect whether a value is eventually used, it could specialize sequence into sequence_ automatically, when it notices that the list is unused.

Change History

Changed 4 months ago by igloo

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to wontfix

Note that with -Wall you get a warning if you ignore a non-() result:

module Q where

f :: IO ()
f = do sequence [putStr "A", putStr "B"]
       putStr "C"
$ ghc -c -O q.hs -fforce-recomp -Wall

q.hs:5:8: Warning:
    A do-notation statement discarded a result of type [()].
    Suppress this warning by saying "_ <- sequence
                                            [putStr "A", putStr "B"]",

Thanks for the suggestion, but I'm not sure it's worth adding a special case to the compiler to do the rewrite - especially as it's not a type-preserving transformation.

Note: See TracTickets for help on using tickets.