Clean up stringify in util/hsc2hs/CrossCodegen
Currently, it's defined
stringify :: String -> String
stringify s = reverse . dropWhile isSpace . reverse -- drop trailing space
. dropWhile isSpace -- drop leading space
. compressSpaces -- replace each span of
-- whitespace with a single space
$ s
where compressSpaces [] = []
compressSpaces (a:as) | isSpace a = ' ' : compressSpaces (dropWhile isSpace as)
compressSpaces (a:as) = a : compressSpaces as
If we're going to go to the trouble of doing this by hand, we might as well take the efficiency advantage doing so can give us:
stringify :: String -> String
-- Spec: stringify = unwords . words
stringify xs = go False (dropWhile isSpace xs)
where
go _haveSpace [] = []
go haveSpace (x:xs)
| isSpace x = go True xs
| otherwise = if haveSpace
then ' ' : x : go False xs
else x : go False xs
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.9 |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Code Coverage |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |