Skip to content

Commit

Permalink
Add Data.Text.show and Data.Text.Lazy.show
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysxia authored and Bodigrim committed Aug 8, 2024
1 parent 1063d61 commit 6ed3cae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ module Data.Text
, zip
, zipWith

-- * Showing values
, show

-- -* Ordered text
-- , sort

Expand All @@ -215,7 +218,7 @@ module Data.Text

import Prelude (Char, Bool(..), Int, Maybe(..), String,
Eq, (==), (/=), Ord(..), Ordering(..), (++),
Monad(..), pure, Read(..),
Monad(..), pure, Read(..), Show,
(&&), (||), (+), (-), (.), ($), ($!), (>>),
not, return, otherwise, quot)
import Control.DeepSeq (NFData(rnf))
Expand Down Expand Up @@ -2050,6 +2053,10 @@ emptyError fun = P.error $ "Data.Text." ++ fun ++ ": empty input"
overflowError :: HasCallStack => String -> a
overflowError fun = P.error $ "Data.Text." ++ fun ++ ": size overflow"

-- | Convert a value to 'Text'.
show :: Show a => a -> Text
show = pack . P.show

-- | /O(n)/ Make a distinct copy of the given string, sharing no
-- storage with the original string.
--
Expand Down
9 changes: 8 additions & 1 deletion src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ module Data.Text.Lazy
, zip
, zipWith

-- * Showing values
, show

-- -* Ordered text
-- , sort
) where

import Prelude (Char, Bool(..), Maybe(..), String,
Eq, (==), Ord(..), Ordering(..), Read(..), Show(..),
Eq, (==), Ord(..), Ordering(..), Read(..), Show(showsPrec),
Monad(..), pure, (<$>),
(&&), (+), (-), (.), ($), (++),
error, flip, fmap, fromIntegral, not, otherwise, quot)
Expand Down Expand Up @@ -1792,6 +1795,10 @@ zipWith f t1 t2 = unstream (S.zipWith g (stream t1) (stream t2))
where g a b = safe (f a b)
{-# INLINE [0] zipWith #-}

-- | Convert a value to lazy 'Text'.
show :: Show a => a -> Text
show = pack . P.show

revChunks :: [T.Text] -> Text
revChunks = L.foldl' (flip chunk) Empty

Expand Down

0 comments on commit 6ed3cae

Please sign in to comment.