Skip to content

Commit

Permalink
Minor update to ByteString Builder Haddock tutorial (#623)
Browse files Browse the repository at this point in the history
Remove redundant imports and the redefinition of (<>).
  • Loading branch information
meooow25 authored Nov 5, 2023
1 parent cb0a01c commit bb6202c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Data/ByteString/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,12 @@ As a simple example of an encoding implementation,
>type Row = [Cell]
>type Table = [Row]
We use the following imports and abbreviate 'mappend' to simplify reading.
We use the following imports.
@
import qualified "Data.ByteString.Lazy" as L
import "Data.ByteString.Builder"
import Data.Monoid
import Data.Foldable ('Data.Foldable.foldMap')
import Data.List ('Data.List.intersperse')
infixr 4 \<\>
(\<\>) :: 'Monoid' m => m -> m -> m
(\<\>) = 'mappend'
@
CSV is a character-based representation of tables. For maximal modularity,
Expand All @@ -79,7 +73,7 @@ encodeUtf8CSV :: Table -> L.ByteString
encodeUtf8CSV = 'toLazyByteString' . renderTable
renderTable :: Table -> Builder
renderTable rs = 'mconcat' [renderRow r \<\> 'charUtf8' \'\\n\' | r <- rs]
renderTable rs = 'mconcat' [renderRow r '<>' 'charUtf8' \'\\n\' | r <- rs]
renderRow :: Row -> Builder
renderRow [] = 'mempty'
Expand All @@ -91,7 +85,7 @@ renderCell (StringC cs) = renderString cs
renderCell (IntC i) = 'intDec' i
renderString :: String -> Builder
renderString cs = charUtf8 \'\"\' \<\> foldMap escape cs \<\> charUtf8 \'\"\'
renderString cs = charUtf8 \'\"\' \<\> 'foldMap' escape cs \<\> charUtf8 \'\"\'
where
escape \'\\\\\' = charUtf8 \'\\\\\' \<\> charUtf8 \'\\\\\'
escape \'\\\"\' = charUtf8 \'\\\\\' \<\> charUtf8 \'\\\"\'
Expand Down

0 comments on commit bb6202c

Please sign in to comment.