Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,334
    • Issues 4,334
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 368
    • Merge Requests 368
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9654

Closed
Open
Opened Oct 01, 2014 by David Feuer@treeowlReporter

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
Assignee
Assign to
7.10.1
Milestone
7.10.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#9654