Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export pack, unpack and Text from Data.Text #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions prettyprinter/bench/LargeOutput.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

Expand All @@ -13,10 +13,10 @@ import Control.Monad.Compat
import Data.Char
import Data.Map (Map)
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL
import Prettyprinter.Util.Compat.Text (Text)
import qualified Prettyprinter.Util.Compat.Text as T
import qualified Prettyprinter.Util.Compat.Text.IO as T
import qualified Prettyprinter.Util.Compat.Text.Lazy as TL
import Prettyprinter
import Prettyprinter.Render.Text
import GHC.Generics
Expand Down
4 changes: 4 additions & 0 deletions prettyprinter/prettyprinter.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ library
, Prettyprinter.Render.Util.SimpleDocTree
, Prettyprinter.Render.Util.StackMachine
, Prettyprinter.Util
, Prettyprinter.Util.Compat.Text
, Prettyprinter.Util.Compat.Text.IO
, Prettyprinter.Util.Compat.Text.Lazy
, Prettyprinter.Util.Compat.Text.Lazy.Builder
Copy link
Owner

@quchen quchen Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will show up on Hackage, cluttering the package overview quite a bit – half of the whole package is already compatibility stuff. I don’t think there’s a way around this, or is there?

Optparse-Applicative is a very popular lib, so allowing Prettyprinter there would be a good thing. But I’m not a fan of cluttering prettyprinter’s public API just so some other package can retain eternal backwards compatibility – why can’t they depend on Text after all? Feels like a pretty strange design decision in anything later than 2010.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps one option is to move these to a separate package altogether?


, Prettyprinter.Symbols.Unicode
, Prettyprinter.Symbols.Ascii
Expand Down
2 changes: 2 additions & 0 deletions prettyprinter/src-text/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ type Text = T.Text
length = T.length
lines = T.lines
toStrict = id
pack = T.pack
unpack = T.unpack
26 changes: 22 additions & 4 deletions prettyprinter/src-text/Data/Text/Lazy/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@

module Data.Text.Lazy.Builder where

type Builder = String
fromText = id
singleton = (:[])
toLazyText = id
import Data.String (IsString (..))
import Data.Semigroup

newtype Builder = Builder (String -> String)
newhoggy marked this conversation as resolved.
Show resolved Hide resolved

instance IsString Builder where
fromString s = Builder (s ++)

instance Semigroup Builder where
Builder a <> Builder b = Builder (a . b)

instance Monoid Builder where
mempty = Builder id

fromText :: String -> Builder
fromText t = Builder (t ++)

singleton :: Char -> Builder
singleton c = Builder ([c] ++)
newhoggy marked this conversation as resolved.
Show resolved Hide resolved

toLazyText :: Builder -> String
toLazyText (Builder b) = b ""
2 changes: 0 additions & 2 deletions prettyprinter/src/Prettyprinter/Render/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

-- | Render an unannotated 'SimpleDocStream' as plain 'Text'.
module Prettyprinter.Render.Text (
#ifdef MIN_VERSION_text
-- * Conversion to plain 'Text'
renderLazy, renderStrict,
#endif

-- * Render to a 'Handle'
renderIO,
Expand Down
11 changes: 11 additions & 0 deletions prettyprinter/src/Prettyprinter/Util/Compat/Text.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- | This module is for use by packages that need to be able to use the prettyprinter package
-- without incurring a dependency on the text package.
--
-- Legitimate examples of packages that must have text as an optional dependency include text (and
-- bytestring).
module Prettyprinter.Util.Compat.Text
sjakobi marked this conversation as resolved.
Show resolved Hide resolved
( module Data.Text
) where

import Data.Text (Text, cons, dropWhileEnd, head, intercalate, length, lines, map, null, pack, replicate,
singleton, snoc, stripEnd, unlines, unpack, words, uncons, splitOn)
10 changes: 10 additions & 0 deletions prettyprinter/src/Prettyprinter/Util/Compat/Text/IO.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- | This module is for use by packages that need to be able to use the prettyprinter package
-- without incurring a dependency on the text package.
--
-- Legitimate examples of packages that must have text as an optional dependency include text (and
-- bytestring).
module Prettyprinter.Util.Compat.Text.IO
( module Data.Text.IO
) where

import Data.Text.IO (hPutStr, putStrLn)
10 changes: 10 additions & 0 deletions prettyprinter/src/Prettyprinter/Util/Compat/Text/Lazy.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- | This module is for use by packages that need to be able to use the prettyprinter package
-- without incurring a dependency on the text package.
--
-- Legitimate examples of packages that must have text as an optional dependency include text (and
-- bytestring).
module Prettyprinter.Util.Compat.Text.Lazy
( module Data.Text.Lazy
) where

import Data.Text.Lazy (Text, length, lines, toStrict, pack, unpack)
10 changes: 10 additions & 0 deletions prettyprinter/src/Prettyprinter/Util/Compat/Text/Lazy/Builder.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- | This module is for use by packages that need to be able to use the prettyprinter package
-- without incurring a dependency on the text package.
--
-- Legitimate examples of packages that must have text as an optional dependency include text (and
-- bytestring).
module Prettyprinter.Util.Compat.Text.Lazy.Builder
( module Data.Text.Lazy.Builder
) where

import Data.Text.Lazy.Builder (Builder (), fromText, singleton, toLazyText)