The GHC tree has many instances of reverse . dropWhile ... . reverse. As well as being harder to read and work with (searching for those forms led me to discover #9616 (closed)) this approach is less efficient than dropWhileEnd. I think I've found all the places this is used, and I'll submit a patch to fix all the instances except for tests and nofib.
Trac metadata
Trac field
Value
Version
7.8.3
Type
Task
TypeOfFailure
OtherFailure
Priority
normal
Resolution
Unresolved
Component
Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
...
Show closed items
Linked items
0
Link issues together to show that they're related or that one is blocking others.
Learn more.
One use of reverse . dropWhile isSpace . reverse turned out to be embedded in what someone suggested correctly was a complete reimplementation of unwords . words, so I just used that.
So dropWhileEnd was not added to base until version 4.5 (ghc 7.4), so to allow compilation with older versions of ghc, it would have to be conditionally imported and defined in the files you changed:
So dropWhileEnd was not added to base until version 4.5 (ghc 7.4), so to allow compilation with older versions of ghc, it would have to be conditionally imported and defined in the files you changed
I'll get on that. Does GHC <7.4 compile GHC 7.9, or can I skip that for the stuff in the compiler?
The patch for hsc2hs looks good to me, but rdr1.diff needs work. If you upload a new version with the same name, it will be overwritten. I don't think you can delete attachments.
This is (relatively) strict in the elements of the list and (relatively) lazy in its spine. This is the opposite of the reverse . dropWhile p . reverse behavior. There should (according to some theory) also be a
that's the other way around. We could call such a thing dropWhileEnd', but that naming convention clashes with another pair of things that should exist and don't:
Criterion has spoken. dropWhileEnd isSpace seems to be much slower in typical cases than even reverse . dropWhile isSpace . reverse. Even a faster predicate, (== ' '), gives a (much smaller) disadvantage to dropWhileEnd.
However, the above dropWhileEndLE appears to be faster than the double reverse in all cases. So I'll add it to the utilities module and use that instead.
However, the above dropWhileEndLE appears to be faster than the double reverse in all cases. So I'll add it to the utilities module and use that instead.
Since dropWhileEndLE is both faster and has less surprising semantics (spine-strict instead of element-strict), I think that the standard library should be changed to use this version. And we should also add takeWhileEnd while we're at it.
However, the above dropWhileEndLE appears to be faster than the double reverse in all cases. So I'll add it to the utilities module and use that instead.
Since dropWhileEndLE is both faster and has less surprising semantics (spine-strict instead of element-strict), I think that the standard library should be changed to use this version. And we should also add takeWhileEnd while we're at it.
It seems to be faster in the common case of trimming spaces from fairly short strings. It would be pretty bad for cutting a little bit off the end of a lazily-read file. I would be in favor of adding dropWhileEndLE (by some name) to Data.List, and perhaps deprecating the name dropWhileEnd in favor of something less confusing like takeUntilLast = dropWhileEnd . not, but just changing the semantics of an existing function seems generally frowned upon. That said, the semantics of Data.Text.Lazy.dropWhileEnd, that someone suggested I check into, are much more confusing to me so far, so there may be a bit of room to wiggle things around.