Skip to content

Commit

Permalink
Merge pull request #7 from 3noch/master
Browse files Browse the repository at this point in the history
Simplify implementation of `string` by not using explicit recursion.
  • Loading branch information
ivan-m committed Oct 28, 2016
2 parents cba5da7 + 7e576be commit 83c1310
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Text/PrettyPrint/Leijen/Text.hs
Expand Up @@ -126,6 +126,7 @@ import Data.String (IsString (..))
import System.IO (Handle, hPutChar, stdout)

import Data.Int (Int64)
import Data.List (intersperse)
import Data.Monoid (Monoid (..), (<>))
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
Expand Down Expand Up @@ -510,11 +511,7 @@ equals = char '='
-- characters. It is used instead of 'text' whenever the text
-- contains newline characters.
string :: Text -> Doc
string str = case T.uncons str of
Nothing -> empty
Just ('\n',str') -> line <> string str'
_ -> case (T.span (/='\n') str) of
(xs,ys) -> text xs <> string ys
string = mconcat . intersperse line . map text . T.lines

-- | The document @(bool b)@ shows the literal boolean @b@ using
-- 'text'.
Expand Down

0 comments on commit 83c1310

Please sign in to comment.