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

Add type synonyms for lazy and strict text flavours #547

Merged
merged 2 commits into from
Dec 13, 2023
Merged
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
3 changes: 2 additions & 1 deletion src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module Data.Text

-- * Types
Text
, StrictText

-- * Creation and elimination
, pack
Expand Down Expand Up @@ -238,7 +239,7 @@ import qualified Data.Text.Internal.Fusion.Common as S
import Data.Text.Encoding (decodeUtf8', encodeUtf8)
import Data.Text.Internal.Fusion (stream, reverseStream, unstream)
import Data.Text.Internal.Private (span_)
import Data.Text.Internal (Text(..), empty, firstf, mul, safe, text, append, pack)
import Data.Text.Internal (Text(..), StrictText, empty, firstf, mul, safe, text, append, pack)
import Data.Text.Internal.Unsafe.Char (unsafeWrite, unsafeChr8)
import Data.Text.Show (singleton, unpack, unpackCString#, unpackCStringAscii#)
import qualified Prelude as P
Expand Down
4 changes: 4 additions & 0 deletions src/Data/Text/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Data.Text.Internal
-- * Types
-- $internals
Text(..)
, StrictText
-- * Construction
, text
, textP
Expand Down Expand Up @@ -68,6 +69,9 @@ data Text = Text
{-# UNPACK #-} !Int -- ^ length in bytes (not in Char!), pointing to an end of UTF-8 sequence
deriving (Typeable)

-- | Type synonym for the strict flavour of 'Text'.
type StrictText = Text

-- | Smart constructor.
text_ ::
#if defined(ASSERTS)
Expand Down
4 changes: 4 additions & 0 deletions src/Data/Text/Internal/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
module Data.Text.Internal.Lazy
(
Text(..)
, LazyText
, chunk
, empty
, foldrChunks
Expand Down Expand Up @@ -51,6 +52,9 @@ data Text = Empty
| Chunk {-# UNPACK #-} !T.Text Text
deriving (Typeable)

-- | Type synonym for the lazy flavour of 'Text'.
type LazyText = Text

-- $invariant
--
-- The data type invariant for lazy 'Text': Every 'Text' is either 'Empty' or
Expand Down
7 changes: 4 additions & 3 deletions src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Data.Text.Lazy

-- * Types
Text
, LazyText

-- * Creation and elimination
, pack
Expand Down Expand Up @@ -230,7 +231,7 @@ import qualified Data.Text.Internal.Lazy.Fusion as S
import Data.Text.Internal.Fusion.Types (PairS(..))
import Data.Text.Internal.Lazy.Fusion (stream, unstream)
import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks,
foldrChunks, smallChunkSize, defaultChunkSize, equal)
foldrChunks, smallChunkSize, defaultChunkSize, equal, LazyText)
import Data.Text.Internal (firstf, safe, text)
import Data.Text.Lazy.Encoding (decodeUtf8', encodeUtf8)
import Data.Text.Internal.Lazy.Search (indices)
Expand Down Expand Up @@ -441,12 +442,12 @@ toChunks :: Text -> [T.Text]
toChunks cs = foldrChunks (:) [] cs

-- | /O(n)/ Convert a lazy 'Text' into a strict 'T.Text'.
toStrict :: Text -> T.Text
toStrict :: LazyText -> T.StrictText
toStrict t = T.concat (toChunks t)
{-# INLINE [1] toStrict #-}

-- | /O(c)/ Convert a strict 'T.Text' into a lazy 'Text'.
fromStrict :: T.Text -> Text
fromStrict :: T.StrictText -> LazyText
fromStrict t = chunk t Empty
{-# INLINE [1] fromStrict #-}

Expand Down
Loading