From 65d8317e8e41cbaff4a3f5466d63257a178d6eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9cate=20Moonlight?= Date: Mon, 27 Nov 2023 11:52:58 +0100 Subject: [PATCH] Add type synonyms for lazy and strict text flavours closes #317 --- src/Data/Text.hs | 4 +++- src/Data/Text/Internal.hs | 4 ++++ src/Data/Text/Internal/Lazy.hs | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Data/Text.hs b/src/Data/Text.hs index 60b1aeda..04bbb429 100644 --- a/src/Data/Text.hs +++ b/src/Data/Text.hs @@ -53,6 +53,8 @@ module Data.Text -- * Types Text + , StrictText + , LazyText -- * Creation and elimination , pack @@ -238,7 +240,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 diff --git a/src/Data/Text/Internal.hs b/src/Data/Text/Internal.hs index 3fc271ea..305d8a3a 100644 --- a/src/Data/Text/Internal.hs +++ b/src/Data/Text/Internal.hs @@ -29,6 +29,7 @@ module Data.Text.Internal -- * Types -- $internals Text(..) + , StrictText -- * Construction , text , textP @@ -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) diff --git a/src/Data/Text/Internal/Lazy.hs b/src/Data/Text/Internal/Lazy.hs index 928e5cfc..12c10699 100644 --- a/src/Data/Text/Internal/Lazy.hs +++ b/src/Data/Text/Internal/Lazy.hs @@ -21,6 +21,7 @@ module Data.Text.Internal.Lazy ( Text(..) + , LazyText , chunk , empty , foldrChunks @@ -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