text-show 1 → 2
raw patch · 189 files changed
+9025/−8863 lines, 189 filesdep ~text-showPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: text-show
API changes (from Hackage documentation)
- Text.Show.Text: FromStringShow :: a -> FromStringShow a
- Text.Show.Text: FromTextShow :: a -> FromTextShow a
- Text.Show.Text: class Show a where showbPrec _ = showb showb = showbPrec 0 showbList = showbListWith showb
- Text.Show.Text: class Show1 f
- Text.Show.Text: class Show2 f
- Text.Show.Text: fromStringShow :: FromStringShow a -> a
- Text.Show.Text: fromTextShow :: FromTextShow a -> a
- Text.Show.Text: hPrint :: Show a => Handle -> a -> IO ()
- Text.Show.Text: hPrintLazy :: Show a => Handle -> a -> IO ()
- Text.Show.Text: lengthB :: Builder -> Int64
- Text.Show.Text: newtype FromStringShow a
- Text.Show.Text: newtype FromTextShow a
- Text.Show.Text: print :: Show a => a -> IO ()
- Text.Show.Text: printLazy :: Show a => a -> IO ()
- Text.Show.Text: show :: Show a => a -> Text
- Text.Show.Text: showLazy :: Show a => a -> Text
- Text.Show.Text: showList :: Show a => [a] -> Text
- Text.Show.Text: showListLazy :: Show a => [a] -> Text
- Text.Show.Text: showPrec :: Show a => Int -> a -> Text
- Text.Show.Text: showPrecLazy :: Show a => Int -> a -> Text
- Text.Show.Text: showb :: Show a => a -> Builder
- Text.Show.Text: showbBinaryWith :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> Builder -> Int -> a -> b -> Builder
- Text.Show.Text: showbList :: Show a => [a] -> Builder
- Text.Show.Text: showbParen :: Bool -> Builder -> Builder
- Text.Show.Text: showbPrec :: Show a => Int -> a -> Builder
- Text.Show.Text: showbPrec1 :: (Show1 f, Show a) => Int -> f a -> Builder
- Text.Show.Text: showbPrec2 :: (Show2 f, Show a, Show b) => Int -> f a b -> Builder
- Text.Show.Text: showbPrecWith :: Show1 f => (Int -> a -> Builder) -> Int -> f a -> Builder
- Text.Show.Text: showbPrecWith2 :: Show2 f => (Int -> a -> Builder) -> (Int -> b -> Builder) -> Int -> f a b -> Builder
- Text.Show.Text: showbSpace :: Builder
- Text.Show.Text: showbUnaryWith :: (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
- Text.Show.Text: toString :: Builder -> String
- Text.Show.Text: toText :: Builder -> Text
- Text.Show.Text: unlinesB :: [Builder] -> Builder
- Text.Show.Text: unwordsB :: [Builder] -> Builder
- Text.Show.Text.Control.Applicative: instance Show a => Show (Const a b)
- Text.Show.Text.Control.Applicative: instance Show a => Show1 (Const a)
- Text.Show.Text.Control.Applicative: instance Show a0 => Show (ZipList a0)
- Text.Show.Text.Control.Applicative: instance Show1 ZipList
- Text.Show.Text.Control.Applicative: instance Show2 Const
- Text.Show.Text.Control.Applicative: showbConstPrecWith :: (Int -> a -> Builder) -> Int -> Const a b -> Builder
- Text.Show.Text.Control.Applicative: showbZipListPrecWith :: (Int -> a -> Builder) -> Int -> ZipList a -> Builder
- Text.Show.Text.Control.Concurrent: instance Show BlockReason
- Text.Show.Text.Control.Concurrent: instance Show ThreadId
- Text.Show.Text.Control.Concurrent: instance Show ThreadStatus
- Text.Show.Text.Control.Concurrent: showbBlockReason :: BlockReason -> Builder
- Text.Show.Text.Control.Concurrent: showbThreadIdPrec :: Int -> ThreadId -> Builder
- Text.Show.Text.Control.Concurrent: showbThreadStatusPrec :: Int -> ThreadStatus -> Builder
- Text.Show.Text.Control.Exception: instance Show ArithException
- Text.Show.Text.Control.Exception: instance Show ArrayException
- Text.Show.Text.Control.Exception: instance Show AssertionFailed
- Text.Show.Text.Control.Exception: instance Show AsyncException
- Text.Show.Text.Control.Exception: instance Show BlockedIndefinitelyOnMVar
- Text.Show.Text.Control.Exception: instance Show BlockedIndefinitelyOnSTM
- Text.Show.Text.Control.Exception: instance Show Deadlock
- Text.Show.Text.Control.Exception: instance Show ErrorCall
- Text.Show.Text.Control.Exception: instance Show IOException
- Text.Show.Text.Control.Exception: instance Show MaskingState
- Text.Show.Text.Control.Exception: instance Show NestedAtomically
- Text.Show.Text.Control.Exception: instance Show NoMethodError
- Text.Show.Text.Control.Exception: instance Show NonTermination
- Text.Show.Text.Control.Exception: instance Show PatternMatchFail
- Text.Show.Text.Control.Exception: instance Show RecConError
- Text.Show.Text.Control.Exception: instance Show RecSelError
- Text.Show.Text.Control.Exception: instance Show RecUpdError
- Text.Show.Text.Control.Exception: instance Show SomeAsyncException
- Text.Show.Text.Control.Exception: instance Show SomeException
- Text.Show.Text.Control.Exception: showbArithException :: ArithException -> Builder
- Text.Show.Text.Control.Exception: showbArrayException :: ArrayException -> Builder
- Text.Show.Text.Control.Exception: showbAssertionFailed :: AssertionFailed -> Builder
- Text.Show.Text.Control.Exception: showbAsyncException :: AsyncException -> Builder
- Text.Show.Text.Control.Exception: showbBlockedIndefinitelyOnMVar :: BlockedIndefinitelyOnMVar -> Builder
- Text.Show.Text.Control.Exception: showbBlockedIndefinitelyOnSTM :: BlockedIndefinitelyOnSTM -> Builder
- Text.Show.Text.Control.Exception: showbDeadlock :: Deadlock -> Builder
- Text.Show.Text.Control.Exception: showbErrorCall :: ErrorCall -> Builder
- Text.Show.Text.Control.Exception: showbIOException :: IOException -> Builder
- Text.Show.Text.Control.Exception: showbMaskingState :: MaskingState -> Builder
- Text.Show.Text.Control.Exception: showbNestedAtomically :: NestedAtomically -> Builder
- Text.Show.Text.Control.Exception: showbNoMethodError :: NoMethodError -> Builder
- Text.Show.Text.Control.Exception: showbNonTermination :: NonTermination -> Builder
- Text.Show.Text.Control.Exception: showbPatternMatchFail :: PatternMatchFail -> Builder
- Text.Show.Text.Control.Exception: showbRecConError :: RecConError -> Builder
- Text.Show.Text.Control.Exception: showbRecSelError :: RecSelError -> Builder
- Text.Show.Text.Control.Exception: showbRecUpdError :: RecUpdError -> Builder
- Text.Show.Text.Control.Exception: showbSomeAsyncException :: SomeAsyncException -> Builder
- Text.Show.Text.Control.Exception: showbSomeExceptionPrec :: Int -> SomeException -> Builder
- Text.Show.Text.Control.Monad.ST: instance Show (ST s a)
- Text.Show.Text.Control.Monad.ST: instance Show1 (ST s)
- Text.Show.Text.Control.Monad.ST: instance Show2 ST
- Text.Show.Text.Control.Monad.ST: showbST :: ST s a -> Builder
- Text.Show.Text.Data.Array: instance (IArray UArray e, Ix i, Show i, Show e) => Show (UArray i e)
- Text.Show.Text.Data.Array: instance (Show i, Show e, Ix i) => Show (Array i e)
- Text.Show.Text.Data.Array: showbArrayPrec :: (Show i, Show e, Ix i) => Int -> Array i e -> Builder
- Text.Show.Text.Data.Array: showbIArrayPrec :: (IArray a e, Ix i, Show i, Show e) => Int -> a i e -> Builder
- Text.Show.Text.Data.Array: showbUArrayPrec :: (IArray UArray e, Ix i, Show i, Show e) => Int -> UArray i e -> Builder
- Text.Show.Text.Data.Bool: instance Show Bool
- Text.Show.Text.Data.Bool: showbBool :: Bool -> Builder
- Text.Show.Text.Data.ByteString: instance Show ByteString
- Text.Show.Text.Data.ByteString: instance Show ShortByteString
- Text.Show.Text.Data.ByteString: showbByteStringLazy :: ByteString -> Builder
- Text.Show.Text.Data.ByteString: showbByteStringLazyPrec :: Int -> ByteString -> Builder
- Text.Show.Text.Data.ByteString: showbByteStringStrict :: ByteString -> Builder
- Text.Show.Text.Data.ByteString: showbShortByteString :: ShortByteString -> Builder
- Text.Show.Text.Data.Char: asciiTabB :: Array Int Builder
- Text.Show.Text.Data.Char: instance Show Char
- Text.Show.Text.Data.Char: instance Show GeneralCategory
- Text.Show.Text.Data.Char: showbChar :: Char -> Builder
- Text.Show.Text.Data.Char: showbGeneralCategory :: GeneralCategory -> Builder
- Text.Show.Text.Data.Char: showbLitChar :: Char -> Builder
- Text.Show.Text.Data.Char: showbLitString :: String -> Builder
- Text.Show.Text.Data.Char: showbString :: String -> Builder
- Text.Show.Text.Data.Complex: instance Show a => Show (Complex a)
- Text.Show.Text.Data.Complex: instance Show1 Complex
- Text.Show.Text.Data.Complex: showbComplexPrec :: Show a => Int -> Complex a -> Builder
- Text.Show.Text.Data.Data: instance Show Constr
- Text.Show.Text.Data.Data: instance Show ConstrRep
- Text.Show.Text.Data.Data: instance Show DataRep
- Text.Show.Text.Data.Data: instance Show DataType
- Text.Show.Text.Data.Data: instance Show Fixity
- Text.Show.Text.Data.Data: showbConstr :: Constr -> Builder
- Text.Show.Text.Data.Data: showbConstrRepPrec :: Int -> ConstrRep -> Builder
- Text.Show.Text.Data.Data: showbDataRepPrec :: Int -> DataRep -> Builder
- Text.Show.Text.Data.Data: showbDataTypePrec :: Int -> DataType -> Builder
- Text.Show.Text.Data.Data: showbFixity :: Fixity -> Builder
- Text.Show.Text.Data.Dynamic: instance Show Dynamic
- Text.Show.Text.Data.Dynamic: showbDynamic :: Dynamic -> Builder
- Text.Show.Text.Data.Either: instance (Show a0, Show b0) => Show (Either a0 b0)
- Text.Show.Text.Data.Either: instance Show a0 => Show1 (Either a0)
- Text.Show.Text.Data.Either: instance Show2 Either
- Text.Show.Text.Data.Either: showbEitherPrecWith2 :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> Int -> Either a b -> Builder
- Text.Show.Text.Data.Fixed: instance HasResolution a => Show (Fixed a)
- Text.Show.Text.Data.Fixed: showbFixed :: HasResolution a => Bool -> Fixed a -> Builder
- Text.Show.Text.Data.Floating: Exponent :: FPFormat
- Text.Show.Text.Data.Floating: Fixed :: FPFormat
- Text.Show.Text.Data.Floating: Generic :: FPFormat
- Text.Show.Text.Data.Floating: data FPFormat :: *
- Text.Show.Text.Data.Floating: formatRealFloatAltB :: RealFloat a => FPFormat -> Maybe Int -> Bool -> a -> Builder
- Text.Show.Text.Data.Floating: formatRealFloatB :: RealFloat a => FPFormat -> Maybe Int -> a -> Builder
- Text.Show.Text.Data.Floating: instance Show Double
- Text.Show.Text.Data.Floating: instance Show FPFormat
- Text.Show.Text.Data.Floating: instance Show Float
- Text.Show.Text.Data.Floating: showbDoublePrec :: Int -> Double -> Builder
- Text.Show.Text.Data.Floating: showbEFloat :: RealFloat a => Maybe Int -> a -> Builder
- Text.Show.Text.Data.Floating: showbFFloat :: RealFloat a => Maybe Int -> a -> Builder
- Text.Show.Text.Data.Floating: showbFFloatAlt :: RealFloat a => Maybe Int -> a -> Builder
- Text.Show.Text.Data.Floating: showbFPFormat :: FPFormat -> Builder
- Text.Show.Text.Data.Floating: showbFloatPrec :: Int -> Float -> Builder
- Text.Show.Text.Data.Floating: showbGFloat :: RealFloat a => Maybe Int -> a -> Builder
- Text.Show.Text.Data.Floating: showbGFloatAlt :: RealFloat a => Maybe Int -> a -> Builder
- Text.Show.Text.Data.Floating: showbRealFloatPrec :: RealFloat a => Int -> a -> Builder
- Text.Show.Text.Data.Functor.Identity: instance Show a => Show (Identity a)
- Text.Show.Text.Data.Functor.Identity: instance Show1 Identity
- Text.Show.Text.Data.Functor.Identity: showbIdentityPrecWith :: (Int -> a -> Builder) -> Int -> Identity a -> Builder
- Text.Show.Text.Data.Integral: instance Show Int
- Text.Show.Text.Data.Integral: instance Show Int16
- Text.Show.Text.Data.Integral: instance Show Int32
- Text.Show.Text.Data.Integral: instance Show Int64
- Text.Show.Text.Data.Integral: instance Show Int8
- Text.Show.Text.Data.Integral: instance Show Integer
- Text.Show.Text.Data.Integral: instance Show Word
- Text.Show.Text.Data.Integral: instance Show Word16
- Text.Show.Text.Data.Integral: instance Show Word32
- Text.Show.Text.Data.Integral: instance Show Word64
- Text.Show.Text.Data.Integral: instance Show Word8
- Text.Show.Text.Data.Integral: showbBin :: (Integral a, Show a) => a -> Builder
- Text.Show.Text.Data.Integral: showbHex :: (Integral a, Show a) => a -> Builder
- Text.Show.Text.Data.Integral: showbInt16Prec :: Int -> Int16 -> Builder
- Text.Show.Text.Data.Integral: showbInt32Prec :: Int -> Int32 -> Builder
- Text.Show.Text.Data.Integral: showbInt64Prec :: Int -> Int64 -> Builder
- Text.Show.Text.Data.Integral: showbInt8Prec :: Int -> Int8 -> Builder
- Text.Show.Text.Data.Integral: showbIntAtBase :: (Integral a, Show a) => a -> (Int -> Char) -> a -> Builder
- Text.Show.Text.Data.Integral: showbIntPrec :: Int -> Int -> Builder
- Text.Show.Text.Data.Integral: showbIntegerPrec :: Int -> Integer -> Builder
- Text.Show.Text.Data.Integral: showbIntegralPrec :: Integral a => Int -> a -> Builder
- Text.Show.Text.Data.Integral: showbOct :: (Integral a, Show a) => a -> Builder
- Text.Show.Text.Data.Integral: showbWord :: Word -> Builder
- Text.Show.Text.Data.Integral: showbWord16 :: Word16 -> Builder
- Text.Show.Text.Data.Integral: showbWord32 :: Word32 -> Builder
- Text.Show.Text.Data.Integral: showbWord64 :: Word64 -> Builder
- Text.Show.Text.Data.Integral: showbWord8 :: Word8 -> Builder
- Text.Show.Text.Data.List: instance Show a => Show [a]
- Text.Show.Text.Data.List: instance Show1 []
- Text.Show.Text.Data.List: showbListWith :: (a -> Builder) -> [a] -> Builder
- Text.Show.Text.Data.Maybe: instance Show a0 => Show (Maybe a0)
- Text.Show.Text.Data.Maybe: instance Show1 Maybe
- Text.Show.Text.Data.Maybe: showbMaybePrecWith :: (Int -> a -> Builder) -> Int -> Maybe a -> Builder
- Text.Show.Text.Data.Monoid: instance Show All
- Text.Show.Text.Data.Monoid: instance Show Any
- Text.Show.Text.Data.Monoid: instance Show a0 => Show (Dual a0)
- Text.Show.Text.Data.Monoid: instance Show a0 => Show (First a0)
- Text.Show.Text.Data.Monoid: instance Show a0 => Show (Last a0)
- Text.Show.Text.Data.Monoid: instance Show a0 => Show (Product a0)
- Text.Show.Text.Data.Monoid: instance Show a0 => Show (Sum a0)
- Text.Show.Text.Data.Monoid: instance Show1 Dual
- Text.Show.Text.Data.Monoid: instance Show1 First
- Text.Show.Text.Data.Monoid: instance Show1 Last
- Text.Show.Text.Data.Monoid: instance Show1 Product
- Text.Show.Text.Data.Monoid: instance Show1 Sum
- Text.Show.Text.Data.Monoid: showbAllPrec :: Int -> All -> Builder
- Text.Show.Text.Data.Monoid: showbAnyPrec :: Int -> Any -> Builder
- Text.Show.Text.Data.Monoid: showbDualPrecWith :: (Int -> a -> Builder) -> Int -> Dual a -> Builder
- Text.Show.Text.Data.Monoid: showbFirstPrecWith :: (Int -> a -> Builder) -> Int -> First a -> Builder
- Text.Show.Text.Data.Monoid: showbLastPrecWith :: (Int -> a -> Builder) -> Int -> Last a -> Builder
- Text.Show.Text.Data.Monoid: showbProductPrecWith :: (Int -> a -> Builder) -> Int -> Product a -> Builder
- Text.Show.Text.Data.Monoid: showbSumPrecWith :: (Int -> a -> Builder) -> Int -> Sum a -> Builder
- Text.Show.Text.Data.OldTypeable: instance Show TyCon
- Text.Show.Text.Data.OldTypeable: instance Show TypeRep
- Text.Show.Text.Data.OldTypeable: showbTyCon :: TyCon -> Builder
- Text.Show.Text.Data.OldTypeable: showbTypeRepPrec :: Int -> TypeRep -> Builder
- Text.Show.Text.Data.Ord: instance Show Ordering
- Text.Show.Text.Data.Ord: instance Show a0 => Show (Down a0)
- Text.Show.Text.Data.Ord: instance Show1 Down
- Text.Show.Text.Data.Ord: showbDownPrecWith :: (Int -> a -> Builder) -> Int -> Down a -> Builder
- Text.Show.Text.Data.Ord: showbOrdering :: Ordering -> Builder
- Text.Show.Text.Data.Proxy: instance Show (Proxy s)
- Text.Show.Text.Data.Proxy: instance Show1 Proxy
- Text.Show.Text.Data.Proxy: showbProxy :: Proxy s -> Builder
- Text.Show.Text.Data.Ratio: instance Show a => Show (Ratio a)
- Text.Show.Text.Data.Ratio: instance Show1 Ratio
- Text.Show.Text.Data.Ratio: showbRatioPrec :: Show a => Int -> Ratio a -> Builder
- Text.Show.Text.Data.Text: instance Show Builder
- Text.Show.Text.Data.Text: instance Show Decoding
- Text.Show.Text.Data.Text: instance Show I16
- Text.Show.Text.Data.Text: instance Show Size
- Text.Show.Text.Data.Text: instance Show Text
- Text.Show.Text.Data.Text: instance Show UnicodeException
- Text.Show.Text.Data.Text: showbBuilder :: Builder -> Builder
- Text.Show.Text.Data.Text: showbDecodingPrec :: Int -> Decoding -> Builder
- Text.Show.Text.Data.Text: showbI16Prec :: Int -> I16 -> Builder
- Text.Show.Text.Data.Text: showbSizePrec :: Int -> Size -> Builder
- Text.Show.Text.Data.Text: showbText :: Text -> Builder
- Text.Show.Text.Data.Text: showbTextLazy :: Text -> Builder
- Text.Show.Text.Data.Text: showbUnicodeException :: UnicodeException -> Builder
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0) => Show (a0, b0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0) => Show1 ((,,) a0 b0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0) => Show2 ((,,,) a0 b0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0) => Show (a0, b0, c0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0) => Show1 ((,,,) a0 b0 c0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0) => Show2 ((,,,,) a0 b0 c0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0) => Show (a0, b0, c0, d0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0) => Show1 ((,,,,) a0 b0 c0 d0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0) => Show2 ((,,,,,) a0 b0 c0 d0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0) => Show (a0, b0, c0, d0, e0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0) => Show1 ((,,,,,) a0 b0 c0 d0 e0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0) => Show2 ((,,,,,,) a0 b0 c0 d0 e0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0) => Show (a0, b0, c0, d0, e0, f0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0) => Show1 ((,,,,,,) a0 b0 c0 d0 e0 f0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0) => Show2 ((,,,,,,,) a0 b0 c0 d0 e0 f0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0) => Show (a0, b0, c0, d0, e0, f0, g0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0) => Show1 ((,,,,,,,) a0 b0 c0 d0 e0 f0 g0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0) => Show2 ((,,,,,,,,) a0 b0 c0 d0 e0 f0 g0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0) => Show (a0, b0, c0, d0, e0, f0, g0, h0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0) => Show1 ((,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0) => Show2 ((,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0) => Show1 ((,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0) => Show2 ((,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0) => Show1 ((,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0) => Show2 ((,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0) => Show1 ((,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0) => Show2 ((,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0) => Show1 ((,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0) => Show2 ((,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0) => Show1 ((,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0) => Show2 ((,,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0, Show n0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0, Show n0) => Show1 ((,,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0 n0)
- Text.Show.Text.Data.Tuple: instance (Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0, Show n0, Show o0) => Show (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0)
- Text.Show.Text.Data.Tuple: instance Show ()
- Text.Show.Text.Data.Tuple: instance Show a0 => Show1 ((,) a0)
- Text.Show.Text.Data.Tuple: instance Show a0 => Show2 ((,,) a0)
- Text.Show.Text.Data.Tuple: instance Show2 (,)
- Text.Show.Text.Data.Tuple: showb10TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => (i -> Builder) -> (j -> Builder) -> (a, b, c, d, e, f, g, h, i, j) -> Builder
- Text.Show.Text.Data.Tuple: showb11TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => (j -> Builder) -> (k -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k) -> Builder
- Text.Show.Text.Data.Tuple: showb12TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => (k -> Builder) -> (l -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Builder
- Text.Show.Text.Data.Tuple: showb13TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => (l -> Builder) -> (m -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Builder
- Text.Show.Text.Data.Tuple: showb14TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => (m -> Builder) -> (n -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Builder
- Text.Show.Text.Data.Tuple: showb15TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => (n -> Builder) -> (o -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Builder
- Text.Show.Text.Data.Tuple: showb2TupleWith2 :: (a -> Builder) -> (b -> Builder) -> (a, b) -> Builder
- Text.Show.Text.Data.Tuple: showb3TupleWith2 :: Show a => (b -> Builder) -> (c -> Builder) -> (a, b, c) -> Builder
- Text.Show.Text.Data.Tuple: showb4TupleWith2 :: (Show a, Show b) => (c -> Builder) -> (d -> Builder) -> (a, b, c, d) -> Builder
- Text.Show.Text.Data.Tuple: showb5TupleWith2 :: (Show a, Show b, Show c) => (d -> Builder) -> (e -> Builder) -> (a, b, c, d, e) -> Builder
- Text.Show.Text.Data.Tuple: showb6TupleWith2 :: (Show a, Show b, Show c, Show d) => (e -> Builder) -> (f -> Builder) -> (a, b, c, d, e, f) -> Builder
- Text.Show.Text.Data.Tuple: showb7TupleWith2 :: (Show a, Show b, Show c, Show d, Show e) => (f -> Builder) -> (g -> Builder) -> (a, b, c, d, e, f, g) -> Builder
- Text.Show.Text.Data.Tuple: showb8TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f) => (g -> Builder) -> (h -> Builder) -> (a, b, c, d, e, f, g, h) -> Builder
- Text.Show.Text.Data.Tuple: showb9TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g) => (h -> Builder) -> (i -> Builder) -> (a, b, c, d, e, f, g, h, i) -> Builder
- Text.Show.Text.Data.Tuple: showbUnit :: () -> Builder
- Text.Show.Text.Data.Type.Coercion: instance Show (Coercion a b)
- Text.Show.Text.Data.Type.Coercion: instance Show1 (Coercion a)
- Text.Show.Text.Data.Type.Coercion: instance Show2 Coercion
- Text.Show.Text.Data.Type.Coercion: showbCoercion :: Coercion a b -> Builder
- Text.Show.Text.Data.Type.Equality: instance Show (a :~: b)
- Text.Show.Text.Data.Type.Equality: instance Show1 ((:~:) a)
- Text.Show.Text.Data.Type.Equality: instance Show2 (:~:)
- Text.Show.Text.Data.Type.Equality: showbPropEquality :: (a :~: b) -> Builder
- Text.Show.Text.Data.Typeable: instance Show TyCon
- Text.Show.Text.Data.Typeable: instance Show TypeRep
- Text.Show.Text.Data.Typeable: showbTyCon :: TyCon -> Builder
- Text.Show.Text.Data.Typeable: showbTypeRepPrec :: Int -> TypeRep -> Builder
- Text.Show.Text.Data.Version: instance Show Version
- Text.Show.Text.Data.Version: showbVersionConcrete :: Version -> Builder
- Text.Show.Text.Data.Version: showbVersionPrec :: Int -> Version -> Builder
- Text.Show.Text.Data.Void: instance Show Void
- Text.Show.Text.Data.Void: showbVoid :: Void -> Builder
- Text.Show.Text.Debug.Trace: trace :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceEvent :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceEventIO :: Text -> IO ()
- Text.Show.Text.Debug.Trace: traceEventIOLazy :: Text -> IO ()
- Text.Show.Text.Debug.Trace: traceEventLazy :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceIO :: Text -> IO ()
- Text.Show.Text.Debug.Trace: traceIOLazy :: Text -> IO ()
- Text.Show.Text.Debug.Trace: traceId :: Text -> Text
- Text.Show.Text.Debug.Trace: traceIdLazy :: Text -> Text
- Text.Show.Text.Debug.Trace: traceLazy :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceM :: Monad m => Text -> m ()
- Text.Show.Text.Debug.Trace: traceMLazy :: Monad m => Text -> m ()
- Text.Show.Text.Debug.Trace: traceMarker :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceMarkerIO :: Text -> IO ()
- Text.Show.Text.Debug.Trace: traceMarkerIOLazy :: Text -> IO ()
- Text.Show.Text.Debug.Trace: traceMarkerLazy :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceShow :: Show a => a -> b -> b
- Text.Show.Text.Debug.Trace: traceShowId :: Show a => a -> a
- Text.Show.Text.Debug.Trace: traceShowM :: (Show a, Monad m) => a -> m ()
- Text.Show.Text.Debug.Trace: traceStack :: Text -> a -> a
- Text.Show.Text.Debug.Trace: traceStackLazy :: Text -> a -> a
- Text.Show.Text.Debug.Trace.Generic: genericTraceShow :: (Generic a, GShow (Rep a)) => a -> b -> b
- Text.Show.Text.Debug.Trace.Generic: genericTraceShowId :: (Generic a, GShow (Rep a)) => a -> a
- Text.Show.Text.Debug.Trace.Generic: genericTraceShowM :: (Generic a, GShow (Rep a), Monad m) => a -> m ()
- Text.Show.Text.Debug.Trace.TH: mkTraceShow :: Name -> Q Exp
- Text.Show.Text.Debug.Trace.TH: mkTraceShowId :: Name -> Q Exp
- Text.Show.Text.Debug.Trace.TH: mkTraceShowM :: Name -> Q Exp
- Text.Show.Text.Foreign.C.Types: instance Show CChar
- Text.Show.Text.Foreign.C.Types: instance Show CClock
- Text.Show.Text.Foreign.C.Types: instance Show CDouble
- Text.Show.Text.Foreign.C.Types: instance Show CFloat
- Text.Show.Text.Foreign.C.Types: instance Show CInt
- Text.Show.Text.Foreign.C.Types: instance Show CIntMax
- Text.Show.Text.Foreign.C.Types: instance Show CIntPtr
- Text.Show.Text.Foreign.C.Types: instance Show CLLong
- Text.Show.Text.Foreign.C.Types: instance Show CLong
- Text.Show.Text.Foreign.C.Types: instance Show CPtrdiff
- Text.Show.Text.Foreign.C.Types: instance Show CSChar
- Text.Show.Text.Foreign.C.Types: instance Show CSUSeconds
- Text.Show.Text.Foreign.C.Types: instance Show CShort
- Text.Show.Text.Foreign.C.Types: instance Show CSigAtomic
- Text.Show.Text.Foreign.C.Types: instance Show CSize
- Text.Show.Text.Foreign.C.Types: instance Show CTime
- Text.Show.Text.Foreign.C.Types: instance Show CUChar
- Text.Show.Text.Foreign.C.Types: instance Show CUInt
- Text.Show.Text.Foreign.C.Types: instance Show CUIntMax
- Text.Show.Text.Foreign.C.Types: instance Show CUIntPtr
- Text.Show.Text.Foreign.C.Types: instance Show CULLong
- Text.Show.Text.Foreign.C.Types: instance Show CULong
- Text.Show.Text.Foreign.C.Types: instance Show CUSeconds
- Text.Show.Text.Foreign.C.Types: instance Show CUShort
- Text.Show.Text.Foreign.C.Types: instance Show CWchar
- Text.Show.Text.Foreign.C.Types: showbCCharPrec :: Int -> CChar -> Builder
- Text.Show.Text.Foreign.C.Types: showbCClockPrec :: Int -> CClock -> Builder
- Text.Show.Text.Foreign.C.Types: showbCDoublePrec :: Int -> CDouble -> Builder
- Text.Show.Text.Foreign.C.Types: showbCFloatPrec :: Int -> CFloat -> Builder
- Text.Show.Text.Foreign.C.Types: showbCIntMaxPrec :: Int -> CIntMax -> Builder
- Text.Show.Text.Foreign.C.Types: showbCIntPrec :: Int -> CInt -> Builder
- Text.Show.Text.Foreign.C.Types: showbCIntPtrPrec :: Int -> CIntPtr -> Builder
- Text.Show.Text.Foreign.C.Types: showbCLLongPrec :: Int -> CLLong -> Builder
- Text.Show.Text.Foreign.C.Types: showbCLongPrec :: Int -> CLong -> Builder
- Text.Show.Text.Foreign.C.Types: showbCPtrdiffPrec :: Int -> CPtrdiff -> Builder
- Text.Show.Text.Foreign.C.Types: showbCSCharPrec :: Int -> CSChar -> Builder
- Text.Show.Text.Foreign.C.Types: showbCSUSecondsPrec :: Int -> CSUSeconds -> Builder
- Text.Show.Text.Foreign.C.Types: showbCShortPrec :: Int -> CShort -> Builder
- Text.Show.Text.Foreign.C.Types: showbCSigAtomicPrec :: Int -> CSigAtomic -> Builder
- Text.Show.Text.Foreign.C.Types: showbCSize :: CSize -> Builder
- Text.Show.Text.Foreign.C.Types: showbCTimePrec :: Int -> CTime -> Builder
- Text.Show.Text.Foreign.C.Types: showbCUChar :: CUChar -> Builder
- Text.Show.Text.Foreign.C.Types: showbCUInt :: CUInt -> Builder
- Text.Show.Text.Foreign.C.Types: showbCUIntMax :: CUIntMax -> Builder
- Text.Show.Text.Foreign.C.Types: showbCUIntPtr :: CUIntPtr -> Builder
- Text.Show.Text.Foreign.C.Types: showbCULLong :: CULLong -> Builder
- Text.Show.Text.Foreign.C.Types: showbCULong :: CULong -> Builder
- Text.Show.Text.Foreign.C.Types: showbCUSeconds :: CUSeconds -> Builder
- Text.Show.Text.Foreign.C.Types: showbCUShort :: CUShort -> Builder
- Text.Show.Text.Foreign.C.Types: showbCWcharPrec :: Int -> CWchar -> Builder
- Text.Show.Text.Foreign.Ptr: instance Show (ForeignPtr a)
- Text.Show.Text.Foreign.Ptr: instance Show (FunPtr a)
- Text.Show.Text.Foreign.Ptr: instance Show (Ptr a)
- Text.Show.Text.Foreign.Ptr: instance Show IntPtr
- Text.Show.Text.Foreign.Ptr: instance Show WordPtr
- Text.Show.Text.Foreign.Ptr: instance Show1 ForeignPtr
- Text.Show.Text.Foreign.Ptr: instance Show1 FunPtr
- Text.Show.Text.Foreign.Ptr: instance Show1 Ptr
- Text.Show.Text.Foreign.Ptr: showbForeignPtr :: ForeignPtr a -> Builder
- Text.Show.Text.Foreign.Ptr: showbFunPtr :: FunPtr a -> Builder
- Text.Show.Text.Foreign.Ptr: showbIntPtrPrec :: Int -> IntPtr -> Builder
- Text.Show.Text.Foreign.Ptr: showbPtr :: Ptr a -> Builder
- Text.Show.Text.Foreign.Ptr: showbWordPtr :: WordPtr -> Builder
- Text.Show.Text.Functions: instance Show (a -> b)
- Text.Show.Text.Functions: instance Show1 ((->) a)
- Text.Show.Text.Functions: instance Show2 (->)
- Text.Show.Text.Functions: showbFunction :: (a -> b) -> Builder
- Text.Show.Text.GHC.Event: instance Show Event
- Text.Show.Text.GHC.Event: instance Show FdKey
- Text.Show.Text.GHC.Event: showbEvent :: Event -> Builder
- Text.Show.Text.GHC.Event: showbFdKeyPrec :: Int -> FdKey -> Builder
- Text.Show.Text.GHC.Fingerprint: instance Show Fingerprint
- Text.Show.Text.GHC.Fingerprint: showbFingerprint :: Fingerprint -> Builder
- Text.Show.Text.GHC.Generics: instance (Show (f p), Show (g p)) => Show ((:*:) f g p)
- Text.Show.Text.GHC.Generics: instance (Show (f p), Show (g p)) => Show ((:+:) f g p)
- Text.Show.Text.GHC.Generics: instance (Show1 f0, Show1 g0) => Show1 (f0 :*: g0)
- Text.Show.Text.GHC.Generics: instance (Show1 f0, Show1 g0) => Show1 (f0 :+: g0)
- Text.Show.Text.GHC.Generics: instance (Show1 f0, Show1 g0) => Show1 (f0 :.: g0)
- Text.Show.Text.GHC.Generics: instance Show (U1 p)
- Text.Show.Text.GHC.Generics: instance Show (f (g p)) => Show ((:.:) f g p)
- Text.Show.Text.GHC.Generics: instance Show (f p) => Show (M1 i c f p)
- Text.Show.Text.GHC.Generics: instance Show (f p) => Show (Rec1 f p)
- Text.Show.Text.GHC.Generics: instance Show Arity
- Text.Show.Text.GHC.Generics: instance Show Associativity
- Text.Show.Text.GHC.Generics: instance Show Fixity
- Text.Show.Text.GHC.Generics: instance Show c => Show (K1 i c p)
- Text.Show.Text.GHC.Generics: instance Show c => Show1 (K1 i c)
- Text.Show.Text.GHC.Generics: instance Show p0 => Show (Par1 p0)
- Text.Show.Text.GHC.Generics: instance Show1 Par1
- Text.Show.Text.GHC.Generics: instance Show1 U1
- Text.Show.Text.GHC.Generics: instance Show1 f => Show1 (M1 i c f)
- Text.Show.Text.GHC.Generics: instance Show1 f0 => Show1 (Rec1 f0)
- Text.Show.Text.GHC.Generics: instance Show2 (K1 i)
- Text.Show.Text.GHC.Generics: showbArityPrec :: Int -> Arity -> Builder
- Text.Show.Text.GHC.Generics: showbAssociativity :: Associativity -> Builder
- Text.Show.Text.GHC.Generics: showbCompFunctorsPrec :: Show (f (g p)) => Int -> (f :.: g) p -> Builder
- Text.Show.Text.GHC.Generics: showbCompFunctorsPrecWith :: (Show1 f, Show1 g) => (Int -> p -> Builder) -> Int -> (f :.: g) p -> Builder
- Text.Show.Text.GHC.Generics: showbFixityPrec :: Int -> Fixity -> Builder
- Text.Show.Text.GHC.Generics: showbK1PrecWith :: (Int -> c -> Builder) -> Int -> K1 i c p -> Builder
- Text.Show.Text.GHC.Generics: showbM1Prec :: Show (f p) => Int -> M1 i c f p -> Builder
- Text.Show.Text.GHC.Generics: showbM1PrecWith :: Show1 f => (Int -> p -> Builder) -> Int -> M1 i c f p -> Builder
- Text.Show.Text.GHC.Generics: showbPar1PrecWith :: (Int -> p -> Builder) -> Int -> Par1 p -> Builder
- Text.Show.Text.GHC.Generics: showbProductTypePrec :: (Show (f p), Show (g p)) => Int -> (f :*: g) p -> Builder
- Text.Show.Text.GHC.Generics: showbProductTypePrecWith :: (Show1 f, Show1 g) => (Int -> p -> Builder) -> Int -> (f :*: g) p -> Builder
- Text.Show.Text.GHC.Generics: showbRec1Prec :: Show (f p) => Int -> Rec1 f p -> Builder
- Text.Show.Text.GHC.Generics: showbRec1PrecWith :: Show1 f => (Int -> p -> Builder) -> Int -> Rec1 f p -> Builder
- Text.Show.Text.GHC.Generics: showbSumTypePrec :: (Show (f p), Show (g p)) => Int -> (f :+: g) p -> Builder
- Text.Show.Text.GHC.Generics: showbSumTypePrecWith :: (Show1 f, Show1 g) => (Int -> p -> Builder) -> Int -> (f :+: g) p -> Builder
- Text.Show.Text.GHC.Generics: showbU1 :: U1 p -> Builder
- Text.Show.Text.GHC.Stats: instance Show GCStats
- Text.Show.Text.GHC.Stats: showbGCStatsPrec :: Int -> GCStats -> Builder
- Text.Show.Text.GHC.TypeLits: instance Show SomeNat
- Text.Show.Text.GHC.TypeLits: instance Show SomeSymbol
- Text.Show.Text.GHC.TypeLits: showbSomeNatPrec :: Int -> SomeNat -> Builder
- Text.Show.Text.GHC.TypeLits: showbSomeSymbol :: SomeSymbol -> Builder
- Text.Show.Text.Generic: Inf :: String -> ConType
- Text.Show.Text.Generic: Pref :: ConType
- Text.Show.Text.Generic: Rec :: ConType
- Text.Show.Text.Generic: Tup :: ConType
- Text.Show.Text.Generic: class GShow f where isNullary = error "generic showbPrec (isNullary): unnecessary case"
- Text.Show.Text.Generic: class GShow1 f where isNullary1 = error "generic showbPrecWith (isNullary1): unnecessary case"
- Text.Show.Text.Generic: data ConType
- Text.Show.Text.Generic: gShowbPrec :: GShow f => ConType -> Int -> f a -> Builder
- Text.Show.Text.Generic: gShowbPrecWith :: GShow1 f => ConType -> (Int -> a -> Builder) -> Int -> f a -> Builder
- Text.Show.Text.Generic: genericHPrint :: (Generic a, GShow (Rep a)) => Handle -> a -> IO ()
- Text.Show.Text.Generic: genericHPrintLazy :: (Generic a, GShow (Rep a)) => Handle -> a -> IO ()
- Text.Show.Text.Generic: genericPrint :: (Generic a, GShow (Rep a)) => a -> IO ()
- Text.Show.Text.Generic: genericPrintLazy :: (Generic a, GShow (Rep a)) => a -> IO ()
- Text.Show.Text.Generic: genericShow :: (Generic a, GShow (Rep a)) => a -> Text
- Text.Show.Text.Generic: genericShowLazy :: (Generic a, GShow (Rep a)) => a -> Text
- Text.Show.Text.Generic: genericShowList :: (Generic a, GShow (Rep a)) => [a] -> Text
- Text.Show.Text.Generic: genericShowListLazy :: (Generic a, GShow (Rep a)) => [a] -> Text
- Text.Show.Text.Generic: genericShowPrec :: (Generic a, GShow (Rep a)) => Int -> a -> Text
- Text.Show.Text.Generic: genericShowPrecLazy :: (Generic a, GShow (Rep a)) => Int -> a -> Text
- Text.Show.Text.Generic: genericShowb :: (Generic a, GShow (Rep a)) => a -> Builder
- Text.Show.Text.Generic: genericShowbList :: (Generic a, GShow (Rep a)) => [a] -> Builder
- Text.Show.Text.Generic: genericShowbPrec :: (Generic a, GShow (Rep a)) => Int -> a -> Builder
- Text.Show.Text.Generic: genericShowbPrec1 :: (Generic a, Generic1 f, GShow (Rep a), GShow1 (Rep1 f)) => Int -> f a -> Builder
- Text.Show.Text.Generic: genericShowbPrecWith :: (Generic1 f, GShow1 (Rep1 f)) => (Int -> a -> Builder) -> Int -> f a -> Builder
- Text.Show.Text.Generic: instance (Constructor c, GShow f) => GShow (C1 c f)
- Text.Show.Text.Generic: instance (Constructor c, GShow1 f) => GShow1 (C1 c f)
- Text.Show.Text.Generic: instance (GShow f, GShow g) => GShow (f :*: g)
- Text.Show.Text.Generic: instance (GShow f, GShow g) => GShow (f :+: g)
- Text.Show.Text.Generic: instance (GShow1 f, GShow1 g) => GShow1 (f :*: g)
- Text.Show.Text.Generic: instance (GShow1 f, GShow1 g) => GShow1 (f :+: g)
- Text.Show.Text.Generic: instance (Selector s, GShow f) => GShow (S1 s f)
- Text.Show.Text.Generic: instance (Selector s, GShow1 f) => GShow1 (S1 s f)
- Text.Show.Text.Generic: instance (Show1 f, GShow1 g) => GShow1 (f :.: g)
- Text.Show.Text.Generic: instance Constructor C1_0ConType
- Text.Show.Text.Generic: instance Constructor C1_1ConType
- Text.Show.Text.Generic: instance Constructor C1_2ConType
- Text.Show.Text.Generic: instance Constructor C1_3ConType
- Text.Show.Text.Generic: instance Datatype D1ConType
- Text.Show.Text.Generic: instance Eq ConType
- Text.Show.Text.Generic: instance GShow U1
- Text.Show.Text.Generic: instance GShow f => GShow (D1 d f)
- Text.Show.Text.Generic: instance GShow1 Par1
- Text.Show.Text.Generic: instance GShow1 U1
- Text.Show.Text.Generic: instance GShow1 f => GShow1 (D1 d f)
- Text.Show.Text.Generic: instance Generic ConType
- Text.Show.Text.Generic: instance Ord ConType
- Text.Show.Text.Generic: instance Read ConType
- Text.Show.Text.Generic: instance Show ConType
- Text.Show.Text.Generic: instance Show c => GShow (K1 i c)
- Text.Show.Text.Generic: instance Show c => GShow1 (K1 i c)
- Text.Show.Text.Generic: instance Show1 f => GShow1 (Rec1 f)
- Text.Show.Text.Generic: instance Typeable ConType
- Text.Show.Text.Generic: instance Typeable GShow
- Text.Show.Text.Generic: instance Typeable GShow1
- Text.Show.Text.Generic: isNullary :: GShow f => f a -> Bool
- Text.Show.Text.Generic: isNullary1 :: GShow1 f => f a -> Bool
- Text.Show.Text.Numeric.Natural: instance Show Natural
- Text.Show.Text.Numeric.Natural: showbNaturalPrec :: Int -> Natural -> Builder
- Text.Show.Text.System.Exit: instance Show ExitCode
- Text.Show.Text.System.Exit: showbExitCodePrec :: Int -> ExitCode -> Builder
- Text.Show.Text.System.IO: instance Show BufferMode
- Text.Show.Text.System.IO: instance Show CodingFailureMode
- Text.Show.Text.System.IO: instance Show CodingProgress
- Text.Show.Text.System.IO: instance Show Handle
- Text.Show.Text.System.IO: instance Show HandlePosn
- Text.Show.Text.System.IO: instance Show IOMode
- Text.Show.Text.System.IO: instance Show Newline
- Text.Show.Text.System.IO: instance Show NewlineMode
- Text.Show.Text.System.IO: instance Show SeekMode
- Text.Show.Text.System.IO: instance Show TextEncoding
- Text.Show.Text.System.IO: showbBufferModePrec :: Int -> BufferMode -> Builder
- Text.Show.Text.System.IO: showbCodingFailureMode :: CodingFailureMode -> Builder
- Text.Show.Text.System.IO: showbCodingProgress :: CodingProgress -> Builder
- Text.Show.Text.System.IO: showbHandle :: Handle -> Builder
- Text.Show.Text.System.IO: showbHandlePosn :: HandlePosn -> Builder
- Text.Show.Text.System.IO: showbIOMode :: IOMode -> Builder
- Text.Show.Text.System.IO: showbNewline :: Newline -> Builder
- Text.Show.Text.System.IO: showbNewlineModePrec :: Int -> NewlineMode -> Builder
- Text.Show.Text.System.IO: showbSeekMode :: SeekMode -> Builder
- Text.Show.Text.System.IO: showbTextEncoding :: TextEncoding -> Builder
- Text.Show.Text.System.Posix.Types: instance Show CCc
- Text.Show.Text.System.Posix.Types: instance Show CDev
- Text.Show.Text.System.Posix.Types: instance Show CGid
- Text.Show.Text.System.Posix.Types: instance Show CIno
- Text.Show.Text.System.Posix.Types: instance Show CMode
- Text.Show.Text.System.Posix.Types: instance Show CNlink
- Text.Show.Text.System.Posix.Types: instance Show COff
- Text.Show.Text.System.Posix.Types: instance Show CPid
- Text.Show.Text.System.Posix.Types: instance Show CRLim
- Text.Show.Text.System.Posix.Types: instance Show CSpeed
- Text.Show.Text.System.Posix.Types: instance Show CSsize
- Text.Show.Text.System.Posix.Types: instance Show CTcflag
- Text.Show.Text.System.Posix.Types: instance Show CUid
- Text.Show.Text.System.Posix.Types: instance Show Fd
- Text.Show.Text.System.Posix.Types: showbCCc :: CCc -> Builder
- Text.Show.Text.System.Posix.Types: showbCDev :: CDev -> Builder
- Text.Show.Text.System.Posix.Types: showbCGid :: CGid -> Builder
- Text.Show.Text.System.Posix.Types: showbCIno :: CIno -> Builder
- Text.Show.Text.System.Posix.Types: showbCMode :: CMode -> Builder
- Text.Show.Text.System.Posix.Types: showbCNlink :: CNlink -> Builder
- Text.Show.Text.System.Posix.Types: showbCOffPrec :: Int -> COff -> Builder
- Text.Show.Text.System.Posix.Types: showbCPidPrec :: Int -> CPid -> Builder
- Text.Show.Text.System.Posix.Types: showbCRLim :: CRLim -> Builder
- Text.Show.Text.System.Posix.Types: showbCSpeed :: CSpeed -> Builder
- Text.Show.Text.System.Posix.Types: showbCSsizePrec :: Int -> CSsize -> Builder
- Text.Show.Text.System.Posix.Types: showbCTcflag :: CTcflag -> Builder
- Text.Show.Text.System.Posix.Types: showbCUid :: CUid -> Builder
- Text.Show.Text.System.Posix.Types: showbFdPrec :: Int -> Fd -> Builder
- Text.Show.Text.TH: deriveShow :: Name -> Q [Dec]
- Text.Show.Text.TH: deriveShow1 :: Name -> Q [Dec]
- Text.Show.Text.TH: deriveShow2 :: Name -> Q [Dec]
- Text.Show.Text.TH: mkHPrint :: Name -> Q Exp
- Text.Show.Text.TH: mkHPrintLazy :: Name -> Q Exp
- Text.Show.Text.TH: mkPrint :: Name -> Q Exp
- Text.Show.Text.TH: mkPrintLazy :: Name -> Q Exp
- Text.Show.Text.TH: mkShow :: Name -> Q Exp
- Text.Show.Text.TH: mkShowLazy :: Name -> Q Exp
- Text.Show.Text.TH: mkShowList :: Name -> Q Exp
- Text.Show.Text.TH: mkShowListLazy :: Name -> Q Exp
- Text.Show.Text.TH: mkShowPrec :: Name -> Q Exp
- Text.Show.Text.TH: mkShowPrecLazy :: Name -> Q Exp
- Text.Show.Text.TH: mkShowb :: Name -> Q Exp
- Text.Show.Text.TH: mkShowbList :: Name -> Q Exp
- Text.Show.Text.TH: mkShowbPrec :: Name -> Q Exp
- Text.Show.Text.TH: mkShowbPrec1 :: Name -> Q Exp
- Text.Show.Text.TH: mkShowbPrec2 :: Name -> Q Exp
- Text.Show.Text.TH: mkShowbPrecWith :: Name -> Q Exp
- Text.Show.Text.TH: mkShowbPrecWith2 :: Name -> Q Exp
- Text.Show.Text.Text.Read: instance Show Lexeme
- Text.Show.Text.Text.Read: instance Show Number
- Text.Show.Text.Text.Read: showbLexemePrec :: Int -> Lexeme -> Builder
- Text.Show.Text.Text.Read: showbNumberPrec :: Int -> Number -> Builder
+ TextShow: FromStringShow :: a -> FromStringShow a
+ TextShow: FromTextShow :: a -> FromTextShow a
+ TextShow: class TextShow a where showbPrec _ = showb showb = showbPrec 0 showbList = showbListWith showb
+ TextShow: class TextShow1 f
+ TextShow: class TextShow2 f
+ TextShow: data Builder :: *
+ TextShow: flush :: Builder
+ TextShow: fromLazyText :: Text -> Builder
+ TextShow: fromString :: String -> Builder
+ TextShow: fromStringShow :: FromStringShow a -> a
+ TextShow: fromText :: Text -> Builder
+ TextShow: fromTextShow :: FromTextShow a -> a
+ TextShow: hPrintT :: TextShow a => Handle -> a -> IO ()
+ TextShow: hPrintTL :: TextShow a => Handle -> a -> IO ()
+ TextShow: lengthB :: Builder -> Int64
+ TextShow: newtype FromStringShow a
+ TextShow: newtype FromTextShow a
+ TextShow: printT :: TextShow a => a -> IO ()
+ TextShow: printTL :: TextShow a => a -> IO ()
+ TextShow: showb :: TextShow a => a -> Builder
+ TextShow: showbBinaryWith :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> Builder -> Int -> a -> b -> Builder
+ TextShow: showbList :: TextShow a => [a] -> Builder
+ TextShow: showbParen :: Bool -> Builder -> Builder
+ TextShow: showbPrec :: TextShow a => Int -> a -> Builder
+ TextShow: showbPrec1 :: (TextShow1 f, TextShow a) => Int -> f a -> Builder
+ TextShow: showbPrec2 :: (TextShow2 f, TextShow a, TextShow b) => Int -> f a b -> Builder
+ TextShow: showbPrecWith :: TextShow1 f => (Int -> a -> Builder) -> Int -> f a -> Builder
+ TextShow: showbPrecWith2 :: TextShow2 f => (Int -> a -> Builder) -> (Int -> b -> Builder) -> Int -> f a b -> Builder
+ TextShow: showbSpace :: Builder
+ TextShow: showbUnaryWith :: (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
+ TextShow: showt :: TextShow a => a -> Text
+ TextShow: showtList :: TextShow a => [a] -> Text
+ TextShow: showtPrec :: TextShow a => Int -> a -> Text
+ TextShow: showtl :: TextShow a => a -> Text
+ TextShow: showtlList :: TextShow a => [a] -> Text
+ TextShow: showtlPrec :: TextShow a => Int -> a -> Text
+ TextShow: singleton :: Char -> Builder
+ TextShow: toLazyText :: Builder -> Text
+ TextShow: toLazyTextWith :: Int -> Builder -> Text
+ TextShow: toString :: Builder -> String
+ TextShow: toText :: Builder -> Text
+ TextShow: unlinesB :: [Builder] -> Builder
+ TextShow: unwordsB :: [Builder] -> Builder
+ TextShow.Control.Applicative: instance TextShow a => TextShow (Const a b)
+ TextShow.Control.Applicative: instance TextShow a => TextShow1 (Const a)
+ TextShow.Control.Applicative: instance TextShow a0 => TextShow (ZipList a0)
+ TextShow.Control.Applicative: instance TextShow1 ZipList
+ TextShow.Control.Applicative: instance TextShow2 Const
+ TextShow.Control.Applicative: showbConstPrecWith :: (Int -> a -> Builder) -> Int -> Const a b -> Builder
+ TextShow.Control.Applicative: showbZipListPrecWith :: (Int -> a -> Builder) -> Int -> ZipList a -> Builder
+ TextShow.Control.Concurrent: instance TextShow BlockReason
+ TextShow.Control.Concurrent: instance TextShow ThreadId
+ TextShow.Control.Concurrent: instance TextShow ThreadStatus
+ TextShow.Control.Concurrent: showbBlockReason :: BlockReason -> Builder
+ TextShow.Control.Concurrent: showbThreadIdPrec :: Int -> ThreadId -> Builder
+ TextShow.Control.Concurrent: showbThreadStatusPrec :: Int -> ThreadStatus -> Builder
+ TextShow.Control.Exception: instance TextShow ArithException
+ TextShow.Control.Exception: instance TextShow ArrayException
+ TextShow.Control.Exception: instance TextShow AssertionFailed
+ TextShow.Control.Exception: instance TextShow AsyncException
+ TextShow.Control.Exception: instance TextShow BlockedIndefinitelyOnMVar
+ TextShow.Control.Exception: instance TextShow BlockedIndefinitelyOnSTM
+ TextShow.Control.Exception: instance TextShow Deadlock
+ TextShow.Control.Exception: instance TextShow ErrorCall
+ TextShow.Control.Exception: instance TextShow IOException
+ TextShow.Control.Exception: instance TextShow MaskingState
+ TextShow.Control.Exception: instance TextShow NestedAtomically
+ TextShow.Control.Exception: instance TextShow NoMethodError
+ TextShow.Control.Exception: instance TextShow NonTermination
+ TextShow.Control.Exception: instance TextShow PatternMatchFail
+ TextShow.Control.Exception: instance TextShow RecConError
+ TextShow.Control.Exception: instance TextShow RecSelError
+ TextShow.Control.Exception: instance TextShow RecUpdError
+ TextShow.Control.Exception: instance TextShow SomeAsyncException
+ TextShow.Control.Exception: instance TextShow SomeException
+ TextShow.Control.Exception: showbArithException :: ArithException -> Builder
+ TextShow.Control.Exception: showbArrayException :: ArrayException -> Builder
+ TextShow.Control.Exception: showbAssertionFailed :: AssertionFailed -> Builder
+ TextShow.Control.Exception: showbAsyncException :: AsyncException -> Builder
+ TextShow.Control.Exception: showbBlockedIndefinitelyOnMVar :: BlockedIndefinitelyOnMVar -> Builder
+ TextShow.Control.Exception: showbBlockedIndefinitelyOnSTM :: BlockedIndefinitelyOnSTM -> Builder
+ TextShow.Control.Exception: showbDeadlock :: Deadlock -> Builder
+ TextShow.Control.Exception: showbErrorCall :: ErrorCall -> Builder
+ TextShow.Control.Exception: showbIOException :: IOException -> Builder
+ TextShow.Control.Exception: showbMaskingState :: MaskingState -> Builder
+ TextShow.Control.Exception: showbNestedAtomically :: NestedAtomically -> Builder
+ TextShow.Control.Exception: showbNoMethodError :: NoMethodError -> Builder
+ TextShow.Control.Exception: showbNonTermination :: NonTermination -> Builder
+ TextShow.Control.Exception: showbPatternMatchFail :: PatternMatchFail -> Builder
+ TextShow.Control.Exception: showbRecConError :: RecConError -> Builder
+ TextShow.Control.Exception: showbRecSelError :: RecSelError -> Builder
+ TextShow.Control.Exception: showbRecUpdError :: RecUpdError -> Builder
+ TextShow.Control.Exception: showbSomeAsyncException :: SomeAsyncException -> Builder
+ TextShow.Control.Exception: showbSomeExceptionPrec :: Int -> SomeException -> Builder
+ TextShow.Control.Monad.ST: instance TextShow (ST s a)
+ TextShow.Control.Monad.ST: instance TextShow1 (ST s)
+ TextShow.Control.Monad.ST: instance TextShow2 ST
+ TextShow.Control.Monad.ST: showbST :: ST s a -> Builder
+ TextShow.Data.Array: instance (IArray UArray e, Ix i, TextShow i, TextShow e) => TextShow (UArray i e)
+ TextShow.Data.Array: instance (TextShow i, TextShow e, Ix i) => TextShow (Array i e)
+ TextShow.Data.Array: showbArrayPrec :: (TextShow i, TextShow e, Ix i) => Int -> Array i e -> Builder
+ TextShow.Data.Array: showbIArrayPrec :: (IArray a e, Ix i, TextShow i, TextShow e) => Int -> a i e -> Builder
+ TextShow.Data.Array: showbUArrayPrec :: (IArray UArray e, Ix i, TextShow i, TextShow e) => Int -> UArray i e -> Builder
+ TextShow.Data.Bool: instance TextShow Bool
+ TextShow.Data.Bool: showbBool :: Bool -> Builder
+ TextShow.Data.ByteString: instance TextShow ByteString
+ TextShow.Data.ByteString: instance TextShow ShortByteString
+ TextShow.Data.ByteString: showbByteStringLazy :: ByteString -> Builder
+ TextShow.Data.ByteString: showbByteStringLazyPrec :: Int -> ByteString -> Builder
+ TextShow.Data.ByteString: showbByteStringStrict :: ByteString -> Builder
+ TextShow.Data.ByteString: showbShortByteString :: ShortByteString -> Builder
+ TextShow.Data.Char: asciiTabB :: Array Int Builder
+ TextShow.Data.Char: instance TextShow Char
+ TextShow.Data.Char: instance TextShow GeneralCategory
+ TextShow.Data.Char: showbChar :: Char -> Builder
+ TextShow.Data.Char: showbGeneralCategory :: GeneralCategory -> Builder
+ TextShow.Data.Char: showbLitChar :: Char -> Builder
+ TextShow.Data.Char: showbLitString :: String -> Builder
+ TextShow.Data.Char: showbString :: String -> Builder
+ TextShow.Data.Complex: instance TextShow a => TextShow (Complex a)
+ TextShow.Data.Complex: instance TextShow1 Complex
+ TextShow.Data.Complex: showbComplexPrec :: TextShow a => Int -> Complex a -> Builder
+ TextShow.Data.Data: instance TextShow Constr
+ TextShow.Data.Data: instance TextShow ConstrRep
+ TextShow.Data.Data: instance TextShow DataRep
+ TextShow.Data.Data: instance TextShow DataType
+ TextShow.Data.Data: instance TextShow Fixity
+ TextShow.Data.Data: showbConstr :: Constr -> Builder
+ TextShow.Data.Data: showbConstrRepPrec :: Int -> ConstrRep -> Builder
+ TextShow.Data.Data: showbDataRepPrec :: Int -> DataRep -> Builder
+ TextShow.Data.Data: showbDataTypePrec :: Int -> DataType -> Builder
+ TextShow.Data.Data: showbFixity :: Fixity -> Builder
+ TextShow.Data.Dynamic: instance TextShow Dynamic
+ TextShow.Data.Dynamic: showbDynamic :: Dynamic -> Builder
+ TextShow.Data.Either: instance (TextShow a0, TextShow b0) => TextShow (Either a0 b0)
+ TextShow.Data.Either: instance TextShow a0 => TextShow1 (Either a0)
+ TextShow.Data.Either: instance TextShow2 Either
+ TextShow.Data.Either: showbEitherPrecWith2 :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> Int -> Either a b -> Builder
+ TextShow.Data.Fixed: instance HasResolution a => TextShow (Fixed a)
+ TextShow.Data.Fixed: showbFixed :: HasResolution a => Bool -> Fixed a -> Builder
+ TextShow.Data.Floating: Exponent :: FPFormat
+ TextShow.Data.Floating: Fixed :: FPFormat
+ TextShow.Data.Floating: Generic :: FPFormat
+ TextShow.Data.Floating: data FPFormat :: *
+ TextShow.Data.Floating: formatRealFloatAltB :: RealFloat a => FPFormat -> Maybe Int -> Bool -> a -> Builder
+ TextShow.Data.Floating: formatRealFloatB :: RealFloat a => FPFormat -> Maybe Int -> a -> Builder
+ TextShow.Data.Floating: instance TextShow Double
+ TextShow.Data.Floating: instance TextShow FPFormat
+ TextShow.Data.Floating: instance TextShow Float
+ TextShow.Data.Floating: showbDoublePrec :: Int -> Double -> Builder
+ TextShow.Data.Floating: showbEFloat :: RealFloat a => Maybe Int -> a -> Builder
+ TextShow.Data.Floating: showbFFloat :: RealFloat a => Maybe Int -> a -> Builder
+ TextShow.Data.Floating: showbFFloatAlt :: RealFloat a => Maybe Int -> a -> Builder
+ TextShow.Data.Floating: showbFPFormat :: FPFormat -> Builder
+ TextShow.Data.Floating: showbFloatPrec :: Int -> Float -> Builder
+ TextShow.Data.Floating: showbGFloat :: RealFloat a => Maybe Int -> a -> Builder
+ TextShow.Data.Floating: showbGFloatAlt :: RealFloat a => Maybe Int -> a -> Builder
+ TextShow.Data.Floating: showbRealFloatPrec :: RealFloat a => Int -> a -> Builder
+ TextShow.Data.Functor.Identity: instance TextShow a => TextShow (Identity a)
+ TextShow.Data.Functor.Identity: instance TextShow1 Identity
+ TextShow.Data.Functor.Identity: showbIdentityPrecWith :: (Int -> a -> Builder) -> Int -> Identity a -> Builder
+ TextShow.Data.Integral: instance TextShow Int
+ TextShow.Data.Integral: instance TextShow Int16
+ TextShow.Data.Integral: instance TextShow Int32
+ TextShow.Data.Integral: instance TextShow Int64
+ TextShow.Data.Integral: instance TextShow Int8
+ TextShow.Data.Integral: instance TextShow Integer
+ TextShow.Data.Integral: instance TextShow Word
+ TextShow.Data.Integral: instance TextShow Word16
+ TextShow.Data.Integral: instance TextShow Word32
+ TextShow.Data.Integral: instance TextShow Word64
+ TextShow.Data.Integral: instance TextShow Word8
+ TextShow.Data.Integral: showbBin :: (Integral a, TextShow a) => a -> Builder
+ TextShow.Data.Integral: showbHex :: (Integral a, TextShow a) => a -> Builder
+ TextShow.Data.Integral: showbInt16Prec :: Int -> Int16 -> Builder
+ TextShow.Data.Integral: showbInt32Prec :: Int -> Int32 -> Builder
+ TextShow.Data.Integral: showbInt64Prec :: Int -> Int64 -> Builder
+ TextShow.Data.Integral: showbInt8Prec :: Int -> Int8 -> Builder
+ TextShow.Data.Integral: showbIntAtBase :: (Integral a, TextShow a) => a -> (Int -> Char) -> a -> Builder
+ TextShow.Data.Integral: showbIntPrec :: Int -> Int -> Builder
+ TextShow.Data.Integral: showbIntegerPrec :: Int -> Integer -> Builder
+ TextShow.Data.Integral: showbIntegralPrec :: Integral a => Int -> a -> Builder
+ TextShow.Data.Integral: showbOct :: (Integral a, TextShow a) => a -> Builder
+ TextShow.Data.Integral: showbWord :: Word -> Builder
+ TextShow.Data.Integral: showbWord16 :: Word16 -> Builder
+ TextShow.Data.Integral: showbWord32 :: Word32 -> Builder
+ TextShow.Data.Integral: showbWord64 :: Word64 -> Builder
+ TextShow.Data.Integral: showbWord8 :: Word8 -> Builder
+ TextShow.Data.List: instance TextShow a => TextShow [a]
+ TextShow.Data.List: instance TextShow1 []
+ TextShow.Data.List: showbListWith :: (a -> Builder) -> [a] -> Builder
+ TextShow.Data.Maybe: instance TextShow a0 => TextShow (Maybe a0)
+ TextShow.Data.Maybe: instance TextShow1 Maybe
+ TextShow.Data.Maybe: showbMaybePrecWith :: (Int -> a -> Builder) -> Int -> Maybe a -> Builder
+ TextShow.Data.Monoid: instance TextShow All
+ TextShow.Data.Monoid: instance TextShow Any
+ TextShow.Data.Monoid: instance TextShow a0 => TextShow (Dual a0)
+ TextShow.Data.Monoid: instance TextShow a0 => TextShow (First a0)
+ TextShow.Data.Monoid: instance TextShow a0 => TextShow (Last a0)
+ TextShow.Data.Monoid: instance TextShow a0 => TextShow (Product a0)
+ TextShow.Data.Monoid: instance TextShow a0 => TextShow (Sum a0)
+ TextShow.Data.Monoid: instance TextShow1 Dual
+ TextShow.Data.Monoid: instance TextShow1 First
+ TextShow.Data.Monoid: instance TextShow1 Last
+ TextShow.Data.Monoid: instance TextShow1 Product
+ TextShow.Data.Monoid: instance TextShow1 Sum
+ TextShow.Data.Monoid: showbAllPrec :: Int -> All -> Builder
+ TextShow.Data.Monoid: showbAnyPrec :: Int -> Any -> Builder
+ TextShow.Data.Monoid: showbDualPrecWith :: (Int -> a -> Builder) -> Int -> Dual a -> Builder
+ TextShow.Data.Monoid: showbFirstPrecWith :: (Int -> a -> Builder) -> Int -> First a -> Builder
+ TextShow.Data.Monoid: showbLastPrecWith :: (Int -> a -> Builder) -> Int -> Last a -> Builder
+ TextShow.Data.Monoid: showbProductPrecWith :: (Int -> a -> Builder) -> Int -> Product a -> Builder
+ TextShow.Data.Monoid: showbSumPrecWith :: (Int -> a -> Builder) -> Int -> Sum a -> Builder
+ TextShow.Data.OldTypeable: instance TextShow TyCon
+ TextShow.Data.OldTypeable: instance TextShow TypeRep
+ TextShow.Data.OldTypeable: showbTyCon :: TyCon -> Builder
+ TextShow.Data.OldTypeable: showbTypeRepPrec :: Int -> TypeRep -> Builder
+ TextShow.Data.Ord: instance TextShow Ordering
+ TextShow.Data.Ord: instance TextShow a0 => TextShow (Down a0)
+ TextShow.Data.Ord: instance TextShow1 Down
+ TextShow.Data.Ord: showbDownPrecWith :: (Int -> a -> Builder) -> Int -> Down a -> Builder
+ TextShow.Data.Ord: showbOrdering :: Ordering -> Builder
+ TextShow.Data.Proxy: instance TextShow (Proxy s)
+ TextShow.Data.Proxy: instance TextShow1 Proxy
+ TextShow.Data.Proxy: showbProxy :: Proxy s -> Builder
+ TextShow.Data.Ratio: instance TextShow a => TextShow (Ratio a)
+ TextShow.Data.Ratio: instance TextShow1 Ratio
+ TextShow.Data.Ratio: showbRatioPrec :: TextShow a => Int -> Ratio a -> Builder
+ TextShow.Data.Text: instance TextShow Builder
+ TextShow.Data.Text: instance TextShow Decoding
+ TextShow.Data.Text: instance TextShow I16
+ TextShow.Data.Text: instance TextShow Size
+ TextShow.Data.Text: instance TextShow Text
+ TextShow.Data.Text: instance TextShow UnicodeException
+ TextShow.Data.Text: showbBuilder :: Builder -> Builder
+ TextShow.Data.Text: showbDecodingPrec :: Int -> Decoding -> Builder
+ TextShow.Data.Text: showbI16Prec :: Int -> I16 -> Builder
+ TextShow.Data.Text: showbSizePrec :: Int -> Size -> Builder
+ TextShow.Data.Text: showbText :: Text -> Builder
+ TextShow.Data.Text: showbTextLazy :: Text -> Builder
+ TextShow.Data.Text: showbUnicodeException :: UnicodeException -> Builder
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0) => TextShow (a0, b0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0) => TextShow1 ((,,) a0 b0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0) => TextShow2 ((,,,) a0 b0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0) => TextShow (a0, b0, c0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0) => TextShow1 ((,,,) a0 b0 c0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0) => TextShow2 ((,,,,) a0 b0 c0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0) => TextShow (a0, b0, c0, d0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0) => TextShow1 ((,,,,) a0 b0 c0 d0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0) => TextShow2 ((,,,,,) a0 b0 c0 d0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0) => TextShow (a0, b0, c0, d0, e0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0) => TextShow1 ((,,,,,) a0 b0 c0 d0 e0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0) => TextShow2 ((,,,,,,) a0 b0 c0 d0 e0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0) => TextShow (a0, b0, c0, d0, e0, f0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0) => TextShow1 ((,,,,,,) a0 b0 c0 d0 e0 f0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0) => TextShow2 ((,,,,,,,) a0 b0 c0 d0 e0 f0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0) => TextShow (a0, b0, c0, d0, e0, f0, g0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0) => TextShow1 ((,,,,,,,) a0 b0 c0 d0 e0 f0 g0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0) => TextShow2 ((,,,,,,,,) a0 b0 c0 d0 e0 f0 g0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0) => TextShow1 ((,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0) => TextShow2 ((,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0) => TextShow1 ((,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0) => TextShow2 ((,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0) => TextShow1 ((,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0) => TextShow2 ((,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0) => TextShow1 ((,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0) => TextShow2 ((,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0) => TextShow1 ((,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0) => TextShow2 ((,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0, TextShow m0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0, TextShow m0) => TextShow1 ((,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0, TextShow m0) => TextShow2 ((,,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0, TextShow m0, TextShow n0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0, TextShow m0, TextShow n0) => TextShow1 ((,,,,,,,,,,,,,,) a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0 n0)
+ TextShow.Data.Tuple: instance (TextShow a0, TextShow b0, TextShow c0, TextShow d0, TextShow e0, TextShow f0, TextShow g0, TextShow h0, TextShow i0, TextShow j0, TextShow k0, TextShow l0, TextShow m0, TextShow n0, TextShow o0) => TextShow (a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0)
+ TextShow.Data.Tuple: instance TextShow ()
+ TextShow.Data.Tuple: instance TextShow a0 => TextShow1 ((,) a0)
+ TextShow.Data.Tuple: instance TextShow a0 => TextShow2 ((,,) a0)
+ TextShow.Data.Tuple: instance TextShow2 (,)
+ TextShow.Data.Tuple: showb10TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h) => (i -> Builder) -> (j -> Builder) -> (a, b, c, d, e, f, g, h, i, j) -> Builder
+ TextShow.Data.Tuple: showb11TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h, TextShow i) => (j -> Builder) -> (k -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k) -> Builder
+ TextShow.Data.Tuple: showb12TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h, TextShow i, TextShow j) => (k -> Builder) -> (l -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Builder
+ TextShow.Data.Tuple: showb13TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h, TextShow i, TextShow j, TextShow k) => (l -> Builder) -> (m -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Builder
+ TextShow.Data.Tuple: showb14TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h, TextShow i, TextShow j, TextShow k, TextShow l) => (m -> Builder) -> (n -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Builder
+ TextShow.Data.Tuple: showb15TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h, TextShow i, TextShow j, TextShow k, TextShow l, TextShow m) => (n -> Builder) -> (o -> Builder) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Builder
+ TextShow.Data.Tuple: showb2TupleWith2 :: (a -> Builder) -> (b -> Builder) -> (a, b) -> Builder
+ TextShow.Data.Tuple: showb3TupleWith2 :: TextShow a => (b -> Builder) -> (c -> Builder) -> (a, b, c) -> Builder
+ TextShow.Data.Tuple: showb4TupleWith2 :: (TextShow a, TextShow b) => (c -> Builder) -> (d -> Builder) -> (a, b, c, d) -> Builder
+ TextShow.Data.Tuple: showb5TupleWith2 :: (TextShow a, TextShow b, TextShow c) => (d -> Builder) -> (e -> Builder) -> (a, b, c, d, e) -> Builder
+ TextShow.Data.Tuple: showb6TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d) => (e -> Builder) -> (f -> Builder) -> (a, b, c, d, e, f) -> Builder
+ TextShow.Data.Tuple: showb7TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e) => (f -> Builder) -> (g -> Builder) -> (a, b, c, d, e, f, g) -> Builder
+ TextShow.Data.Tuple: showb8TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f) => (g -> Builder) -> (h -> Builder) -> (a, b, c, d, e, f, g, h) -> Builder
+ TextShow.Data.Tuple: showb9TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g) => (h -> Builder) -> (i -> Builder) -> (a, b, c, d, e, f, g, h, i) -> Builder
+ TextShow.Data.Tuple: showbUnit :: () -> Builder
+ TextShow.Data.Type.Coercion: instance TextShow (Coercion a b)
+ TextShow.Data.Type.Coercion: instance TextShow1 (Coercion a)
+ TextShow.Data.Type.Coercion: instance TextShow2 Coercion
+ TextShow.Data.Type.Coercion: showbCoercion :: Coercion a b -> Builder
+ TextShow.Data.Type.Equality: instance TextShow (a :~: b)
+ TextShow.Data.Type.Equality: instance TextShow1 ((:~:) a)
+ TextShow.Data.Type.Equality: instance TextShow2 (:~:)
+ TextShow.Data.Type.Equality: showbPropEquality :: (a :~: b) -> Builder
+ TextShow.Data.Typeable: instance TextShow TyCon
+ TextShow.Data.Typeable: instance TextShow TypeRep
+ TextShow.Data.Typeable: showbTyCon :: TyCon -> Builder
+ TextShow.Data.Typeable: showbTypeRepPrec :: Int -> TypeRep -> Builder
+ TextShow.Data.Version: instance TextShow Version
+ TextShow.Data.Version: showbVersionConcrete :: Version -> Builder
+ TextShow.Data.Version: showbVersionPrec :: Int -> Version -> Builder
+ TextShow.Data.Void: instance TextShow Void
+ TextShow.Data.Void: showbVoid :: Void -> Builder
+ TextShow.Debug.Trace: traceTextShow :: TextShow a => a -> b -> b
+ TextShow.Debug.Trace: traceTextShowId :: TextShow a => a -> a
+ TextShow.Debug.Trace: traceTextShowM :: (TextShow a, Applicative f) => a -> f ()
+ TextShow.Debug.Trace: tracet :: Text -> a -> a
+ TextShow.Debug.Trace: tracetEvent :: Text -> a -> a
+ TextShow.Debug.Trace: tracetEventIO :: Text -> IO ()
+ TextShow.Debug.Trace: tracetIO :: Text -> IO ()
+ TextShow.Debug.Trace: tracetId :: Text -> Text
+ TextShow.Debug.Trace: tracetM :: Applicative f => Text -> f ()
+ TextShow.Debug.Trace: tracetMarker :: Text -> a -> a
+ TextShow.Debug.Trace: tracetMarkerIO :: Text -> IO ()
+ TextShow.Debug.Trace: tracetStack :: Text -> a -> a
+ TextShow.Debug.Trace: tracetl :: Text -> a -> a
+ TextShow.Debug.Trace: tracetlEvent :: Text -> a -> a
+ TextShow.Debug.Trace: tracetlEventIO :: Text -> IO ()
+ TextShow.Debug.Trace: tracetlIO :: Text -> IO ()
+ TextShow.Debug.Trace: tracetlId :: Text -> Text
+ TextShow.Debug.Trace: tracetlM :: Applicative f => Text -> f ()
+ TextShow.Debug.Trace: tracetlMarker :: Text -> a -> a
+ TextShow.Debug.Trace: tracetlMarkerIO :: Text -> IO ()
+ TextShow.Debug.Trace: tracetlStack :: Text -> a -> a
+ TextShow.Debug.Trace.Generic: genericTraceTextShow :: (Generic a, GTextShow (Rep a)) => a -> b -> b
+ TextShow.Debug.Trace.Generic: genericTraceTextShowId :: (Generic a, GTextShow (Rep a)) => a -> a
+ TextShow.Debug.Trace.Generic: genericTraceTextShowM :: (Generic a, GTextShow (Rep a), Applicative f) => a -> f ()
+ TextShow.Debug.Trace.TH: makeTraceTextShow :: Name -> Q Exp
+ TextShow.Debug.Trace.TH: makeTraceTextShowId :: Name -> Q Exp
+ TextShow.Debug.Trace.TH: makeTraceTextShowM :: Name -> Q Exp
+ TextShow.Foreign.C.Types: instance TextShow CChar
+ TextShow.Foreign.C.Types: instance TextShow CClock
+ TextShow.Foreign.C.Types: instance TextShow CDouble
+ TextShow.Foreign.C.Types: instance TextShow CFloat
+ TextShow.Foreign.C.Types: instance TextShow CInt
+ TextShow.Foreign.C.Types: instance TextShow CIntMax
+ TextShow.Foreign.C.Types: instance TextShow CIntPtr
+ TextShow.Foreign.C.Types: instance TextShow CLLong
+ TextShow.Foreign.C.Types: instance TextShow CLong
+ TextShow.Foreign.C.Types: instance TextShow CPtrdiff
+ TextShow.Foreign.C.Types: instance TextShow CSChar
+ TextShow.Foreign.C.Types: instance TextShow CSUSeconds
+ TextShow.Foreign.C.Types: instance TextShow CShort
+ TextShow.Foreign.C.Types: instance TextShow CSigAtomic
+ TextShow.Foreign.C.Types: instance TextShow CSize
+ TextShow.Foreign.C.Types: instance TextShow CTime
+ TextShow.Foreign.C.Types: instance TextShow CUChar
+ TextShow.Foreign.C.Types: instance TextShow CUInt
+ TextShow.Foreign.C.Types: instance TextShow CUIntMax
+ TextShow.Foreign.C.Types: instance TextShow CUIntPtr
+ TextShow.Foreign.C.Types: instance TextShow CULLong
+ TextShow.Foreign.C.Types: instance TextShow CULong
+ TextShow.Foreign.C.Types: instance TextShow CUSeconds
+ TextShow.Foreign.C.Types: instance TextShow CUShort
+ TextShow.Foreign.C.Types: instance TextShow CWchar
+ TextShow.Foreign.C.Types: showbCCharPrec :: Int -> CChar -> Builder
+ TextShow.Foreign.C.Types: showbCClockPrec :: Int -> CClock -> Builder
+ TextShow.Foreign.C.Types: showbCDoublePrec :: Int -> CDouble -> Builder
+ TextShow.Foreign.C.Types: showbCFloatPrec :: Int -> CFloat -> Builder
+ TextShow.Foreign.C.Types: showbCIntMaxPrec :: Int -> CIntMax -> Builder
+ TextShow.Foreign.C.Types: showbCIntPrec :: Int -> CInt -> Builder
+ TextShow.Foreign.C.Types: showbCIntPtrPrec :: Int -> CIntPtr -> Builder
+ TextShow.Foreign.C.Types: showbCLLongPrec :: Int -> CLLong -> Builder
+ TextShow.Foreign.C.Types: showbCLongPrec :: Int -> CLong -> Builder
+ TextShow.Foreign.C.Types: showbCPtrdiffPrec :: Int -> CPtrdiff -> Builder
+ TextShow.Foreign.C.Types: showbCSCharPrec :: Int -> CSChar -> Builder
+ TextShow.Foreign.C.Types: showbCSUSecondsPrec :: Int -> CSUSeconds -> Builder
+ TextShow.Foreign.C.Types: showbCShortPrec :: Int -> CShort -> Builder
+ TextShow.Foreign.C.Types: showbCSigAtomicPrec :: Int -> CSigAtomic -> Builder
+ TextShow.Foreign.C.Types: showbCSize :: CSize -> Builder
+ TextShow.Foreign.C.Types: showbCTimePrec :: Int -> CTime -> Builder
+ TextShow.Foreign.C.Types: showbCUChar :: CUChar -> Builder
+ TextShow.Foreign.C.Types: showbCUInt :: CUInt -> Builder
+ TextShow.Foreign.C.Types: showbCUIntMax :: CUIntMax -> Builder
+ TextShow.Foreign.C.Types: showbCUIntPtr :: CUIntPtr -> Builder
+ TextShow.Foreign.C.Types: showbCULLong :: CULLong -> Builder
+ TextShow.Foreign.C.Types: showbCULong :: CULong -> Builder
+ TextShow.Foreign.C.Types: showbCUSeconds :: CUSeconds -> Builder
+ TextShow.Foreign.C.Types: showbCUShort :: CUShort -> Builder
+ TextShow.Foreign.C.Types: showbCWcharPrec :: Int -> CWchar -> Builder
+ TextShow.Foreign.Ptr: instance TextShow (ForeignPtr a)
+ TextShow.Foreign.Ptr: instance TextShow (FunPtr a)
+ TextShow.Foreign.Ptr: instance TextShow (Ptr a)
+ TextShow.Foreign.Ptr: instance TextShow IntPtr
+ TextShow.Foreign.Ptr: instance TextShow WordPtr
+ TextShow.Foreign.Ptr: instance TextShow1 ForeignPtr
+ TextShow.Foreign.Ptr: instance TextShow1 FunPtr
+ TextShow.Foreign.Ptr: instance TextShow1 Ptr
+ TextShow.Foreign.Ptr: showbForeignPtr :: ForeignPtr a -> Builder
+ TextShow.Foreign.Ptr: showbFunPtr :: FunPtr a -> Builder
+ TextShow.Foreign.Ptr: showbIntPtrPrec :: Int -> IntPtr -> Builder
+ TextShow.Foreign.Ptr: showbPtr :: Ptr a -> Builder
+ TextShow.Foreign.Ptr: showbWordPtr :: WordPtr -> Builder
+ TextShow.Functions: instance TextShow (a -> b)
+ TextShow.Functions: instance TextShow1 ((->) a)
+ TextShow.Functions: instance TextShow2 (->)
+ TextShow.Functions: showbFunction :: (a -> b) -> Builder
+ TextShow.GHC.Event: instance TextShow Event
+ TextShow.GHC.Event: instance TextShow FdKey
+ TextShow.GHC.Event: showbEvent :: Event -> Builder
+ TextShow.GHC.Event: showbFdKeyPrec :: Int -> FdKey -> Builder
+ TextShow.GHC.Fingerprint: instance TextShow Fingerprint
+ TextShow.GHC.Fingerprint: showbFingerprint :: Fingerprint -> Builder
+ TextShow.GHC.Generics: instance (TextShow (f p), TextShow (g p)) => TextShow ((:*:) f g p)
+ TextShow.GHC.Generics: instance (TextShow (f p), TextShow (g p)) => TextShow ((:+:) f g p)
+ TextShow.GHC.Generics: instance (TextShow1 f0, TextShow1 g0) => TextShow1 (f0 :*: g0)
+ TextShow.GHC.Generics: instance (TextShow1 f0, TextShow1 g0) => TextShow1 (f0 :+: g0)
+ TextShow.GHC.Generics: instance (TextShow1 f0, TextShow1 g0) => TextShow1 (f0 :.: g0)
+ TextShow.GHC.Generics: instance TextShow (U1 p)
+ TextShow.GHC.Generics: instance TextShow (f (g p)) => TextShow ((:.:) f g p)
+ TextShow.GHC.Generics: instance TextShow (f p) => TextShow (M1 i c f p)
+ TextShow.GHC.Generics: instance TextShow (f p) => TextShow (Rec1 f p)
+ TextShow.GHC.Generics: instance TextShow Arity
+ TextShow.GHC.Generics: instance TextShow Associativity
+ TextShow.GHC.Generics: instance TextShow Fixity
+ TextShow.GHC.Generics: instance TextShow c => TextShow (K1 i c p)
+ TextShow.GHC.Generics: instance TextShow c => TextShow1 (K1 i c)
+ TextShow.GHC.Generics: instance TextShow p0 => TextShow (Par1 p0)
+ TextShow.GHC.Generics: instance TextShow1 Par1
+ TextShow.GHC.Generics: instance TextShow1 U1
+ TextShow.GHC.Generics: instance TextShow1 f => TextShow1 (M1 i c f)
+ TextShow.GHC.Generics: instance TextShow1 f0 => TextShow1 (Rec1 f0)
+ TextShow.GHC.Generics: instance TextShow2 (K1 i)
+ TextShow.GHC.Generics: showbArityPrec :: Int -> Arity -> Builder
+ TextShow.GHC.Generics: showbAssociativity :: Associativity -> Builder
+ TextShow.GHC.Generics: showbCompFunctorsPrec :: TextShow (f (g p)) => Int -> (f :.: g) p -> Builder
+ TextShow.GHC.Generics: showbCompFunctorsPrecWith :: (TextShow1 f, TextShow1 g) => (Int -> p -> Builder) -> Int -> (f :.: g) p -> Builder
+ TextShow.GHC.Generics: showbFixityPrec :: Int -> Fixity -> Builder
+ TextShow.GHC.Generics: showbK1PrecWith :: (Int -> c -> Builder) -> Int -> K1 i c p -> Builder
+ TextShow.GHC.Generics: showbM1Prec :: TextShow (f p) => Int -> M1 i c f p -> Builder
+ TextShow.GHC.Generics: showbM1PrecWith :: TextShow1 f => (Int -> p -> Builder) -> Int -> M1 i c f p -> Builder
+ TextShow.GHC.Generics: showbPar1PrecWith :: (Int -> p -> Builder) -> Int -> Par1 p -> Builder
+ TextShow.GHC.Generics: showbProductTypePrec :: (TextShow (f p), TextShow (g p)) => Int -> (f :*: g) p -> Builder
+ TextShow.GHC.Generics: showbProductTypePrecWith :: (TextShow1 f, TextShow1 g) => (Int -> p -> Builder) -> Int -> (f :*: g) p -> Builder
+ TextShow.GHC.Generics: showbRec1Prec :: TextShow (f p) => Int -> Rec1 f p -> Builder
+ TextShow.GHC.Generics: showbRec1PrecWith :: TextShow1 f => (Int -> p -> Builder) -> Int -> Rec1 f p -> Builder
+ TextShow.GHC.Generics: showbSumTypePrec :: (TextShow (f p), TextShow (g p)) => Int -> (f :+: g) p -> Builder
+ TextShow.GHC.Generics: showbSumTypePrecWith :: (TextShow1 f, TextShow1 g) => (Int -> p -> Builder) -> Int -> (f :+: g) p -> Builder
+ TextShow.GHC.Generics: showbU1 :: U1 p -> Builder
+ TextShow.GHC.Stats: instance TextShow GCStats
+ TextShow.GHC.Stats: showbGCStatsPrec :: Int -> GCStats -> Builder
+ TextShow.GHC.TypeLits: instance TextShow SomeNat
+ TextShow.GHC.TypeLits: instance TextShow SomeSymbol
+ TextShow.GHC.TypeLits: showbSomeNatPrec :: Int -> SomeNat -> Builder
+ TextShow.GHC.TypeLits: showbSomeSymbol :: SomeSymbol -> Builder
+ TextShow.Generic: Inf :: String -> ConType
+ TextShow.Generic: Pref :: ConType
+ TextShow.Generic: Rec :: ConType
+ TextShow.Generic: Tup :: ConType
+ TextShow.Generic: class GTextShow f where isNullary = error "generic showbPrec (isNullary): unnecessary case"
+ TextShow.Generic: class GTextShow1 f where isNullary1 = error "generic showbPrecWith (isNullary1): unnecessary case"
+ TextShow.Generic: data ConType
+ TextShow.Generic: gShowbPrec :: GTextShow f => ConType -> Int -> f a -> Builder
+ TextShow.Generic: gShowbPrecWith :: GTextShow1 f => ConType -> (Int -> a -> Builder) -> Int -> f a -> Builder
+ TextShow.Generic: genericHPrintT :: (Generic a, GTextShow (Rep a)) => Handle -> a -> IO ()
+ TextShow.Generic: genericHPrintTL :: (Generic a, GTextShow (Rep a)) => Handle -> a -> IO ()
+ TextShow.Generic: genericPrintT :: (Generic a, GTextShow (Rep a)) => a -> IO ()
+ TextShow.Generic: genericPrintTL :: (Generic a, GTextShow (Rep a)) => a -> IO ()
+ TextShow.Generic: genericShowb :: (Generic a, GTextShow (Rep a)) => a -> Builder
+ TextShow.Generic: genericShowbList :: (Generic a, GTextShow (Rep a)) => [a] -> Builder
+ TextShow.Generic: genericShowbPrec :: (Generic a, GTextShow (Rep a)) => Int -> a -> Builder
+ TextShow.Generic: genericShowbPrec1 :: (Generic a, Generic1 f, GTextShow (Rep a), GTextShow1 (Rep1 f)) => Int -> f a -> Builder
+ TextShow.Generic: genericShowbPrecWith :: (Generic1 f, GTextShow1 (Rep1 f)) => (Int -> a -> Builder) -> Int -> f a -> Builder
+ TextShow.Generic: genericShowt :: (Generic a, GTextShow (Rep a)) => a -> Text
+ TextShow.Generic: genericShowtList :: (Generic a, GTextShow (Rep a)) => [a] -> Text
+ TextShow.Generic: genericShowtPrec :: (Generic a, GTextShow (Rep a)) => Int -> a -> Text
+ TextShow.Generic: genericShowtl :: (Generic a, GTextShow (Rep a)) => a -> Text
+ TextShow.Generic: genericShowtlList :: (Generic a, GTextShow (Rep a)) => [a] -> Text
+ TextShow.Generic: genericShowtlPrec :: (Generic a, GTextShow (Rep a)) => Int -> a -> Text
+ TextShow.Generic: instance (Constructor c, GTextShow f) => GTextShow (C1 c f)
+ TextShow.Generic: instance (Constructor c, GTextShow1 f) => GTextShow1 (C1 c f)
+ TextShow.Generic: instance (GTextShow f, GTextShow g) => GTextShow (f :*: g)
+ TextShow.Generic: instance (GTextShow f, GTextShow g) => GTextShow (f :+: g)
+ TextShow.Generic: instance (GTextShow1 f, GTextShow1 g) => GTextShow1 (f :*: g)
+ TextShow.Generic: instance (GTextShow1 f, GTextShow1 g) => GTextShow1 (f :+: g)
+ TextShow.Generic: instance (Selector s, GTextShow f) => GTextShow (S1 s f)
+ TextShow.Generic: instance (Selector s, GTextShow1 f) => GTextShow1 (S1 s f)
+ TextShow.Generic: instance (TextShow1 f, GTextShow1 g) => GTextShow1 (f :.: g)
+ TextShow.Generic: instance Constructor C1_0ConType
+ TextShow.Generic: instance Constructor C1_1ConType
+ TextShow.Generic: instance Constructor C1_2ConType
+ TextShow.Generic: instance Constructor C1_3ConType
+ TextShow.Generic: instance Datatype D1ConType
+ TextShow.Generic: instance Eq ConType
+ TextShow.Generic: instance GTextShow U1
+ TextShow.Generic: instance GTextShow f => GTextShow (D1 d f)
+ TextShow.Generic: instance GTextShow1 Par1
+ TextShow.Generic: instance GTextShow1 U1
+ TextShow.Generic: instance GTextShow1 f => GTextShow1 (D1 d f)
+ TextShow.Generic: instance Generic ConType
+ TextShow.Generic: instance Ord ConType
+ TextShow.Generic: instance Read ConType
+ TextShow.Generic: instance Show ConType
+ TextShow.Generic: instance TextShow ConType
+ TextShow.Generic: instance TextShow c => GTextShow (K1 i c)
+ TextShow.Generic: instance TextShow c => GTextShow1 (K1 i c)
+ TextShow.Generic: instance TextShow1 f => GTextShow1 (Rec1 f)
+ TextShow.Generic: instance Typeable ConType
+ TextShow.Generic: instance Typeable GTextShow
+ TextShow.Generic: instance Typeable GTextShow1
+ TextShow.Generic: isNullary :: GTextShow f => f a -> Bool
+ TextShow.Generic: isNullary1 :: GTextShow1 f => f a -> Bool
+ TextShow.Numeric.Natural: instance TextShow Natural
+ TextShow.Numeric.Natural: showbNaturalPrec :: Int -> Natural -> Builder
+ TextShow.System.Exit: instance TextShow ExitCode
+ TextShow.System.Exit: showbExitCodePrec :: Int -> ExitCode -> Builder
+ TextShow.System.IO: instance TextShow BufferMode
+ TextShow.System.IO: instance TextShow CodingFailureMode
+ TextShow.System.IO: instance TextShow CodingProgress
+ TextShow.System.IO: instance TextShow Handle
+ TextShow.System.IO: instance TextShow HandlePosn
+ TextShow.System.IO: instance TextShow IOMode
+ TextShow.System.IO: instance TextShow Newline
+ TextShow.System.IO: instance TextShow NewlineMode
+ TextShow.System.IO: instance TextShow SeekMode
+ TextShow.System.IO: instance TextShow TextEncoding
+ TextShow.System.IO: showbBufferModePrec :: Int -> BufferMode -> Builder
+ TextShow.System.IO: showbCodingFailureMode :: CodingFailureMode -> Builder
+ TextShow.System.IO: showbCodingProgress :: CodingProgress -> Builder
+ TextShow.System.IO: showbHandle :: Handle -> Builder
+ TextShow.System.IO: showbHandlePosn :: HandlePosn -> Builder
+ TextShow.System.IO: showbIOMode :: IOMode -> Builder
+ TextShow.System.IO: showbNewline :: Newline -> Builder
+ TextShow.System.IO: showbNewlineModePrec :: Int -> NewlineMode -> Builder
+ TextShow.System.IO: showbSeekMode :: SeekMode -> Builder
+ TextShow.System.IO: showbTextEncoding :: TextEncoding -> Builder
+ TextShow.System.Posix.Types: instance TextShow CCc
+ TextShow.System.Posix.Types: instance TextShow CDev
+ TextShow.System.Posix.Types: instance TextShow CGid
+ TextShow.System.Posix.Types: instance TextShow CIno
+ TextShow.System.Posix.Types: instance TextShow CMode
+ TextShow.System.Posix.Types: instance TextShow CNlink
+ TextShow.System.Posix.Types: instance TextShow COff
+ TextShow.System.Posix.Types: instance TextShow CPid
+ TextShow.System.Posix.Types: instance TextShow CRLim
+ TextShow.System.Posix.Types: instance TextShow CSpeed
+ TextShow.System.Posix.Types: instance TextShow CSsize
+ TextShow.System.Posix.Types: instance TextShow CTcflag
+ TextShow.System.Posix.Types: instance TextShow CUid
+ TextShow.System.Posix.Types: instance TextShow Fd
+ TextShow.System.Posix.Types: showbCCc :: CCc -> Builder
+ TextShow.System.Posix.Types: showbCDev :: CDev -> Builder
+ TextShow.System.Posix.Types: showbCGid :: CGid -> Builder
+ TextShow.System.Posix.Types: showbCIno :: CIno -> Builder
+ TextShow.System.Posix.Types: showbCMode :: CMode -> Builder
+ TextShow.System.Posix.Types: showbCNlink :: CNlink -> Builder
+ TextShow.System.Posix.Types: showbCOffPrec :: Int -> COff -> Builder
+ TextShow.System.Posix.Types: showbCPidPrec :: Int -> CPid -> Builder
+ TextShow.System.Posix.Types: showbCRLim :: CRLim -> Builder
+ TextShow.System.Posix.Types: showbCSpeed :: CSpeed -> Builder
+ TextShow.System.Posix.Types: showbCSsizePrec :: Int -> CSsize -> Builder
+ TextShow.System.Posix.Types: showbCTcflag :: CTcflag -> Builder
+ TextShow.System.Posix.Types: showbCUid :: CUid -> Builder
+ TextShow.System.Posix.Types: showbFdPrec :: Int -> Fd -> Builder
+ TextShow.TH: deriveTextShow :: Name -> Q [Dec]
+ TextShow.TH: deriveTextShow1 :: Name -> Q [Dec]
+ TextShow.TH: deriveTextShow2 :: Name -> Q [Dec]
+ TextShow.TH: makeHPrintT :: Name -> Q Exp
+ TextShow.TH: makeHPrintTL :: Name -> Q Exp
+ TextShow.TH: makePrintT :: Name -> Q Exp
+ TextShow.TH: makePrintTL :: Name -> Q Exp
+ TextShow.TH: makeShowb :: Name -> Q Exp
+ TextShow.TH: makeShowbList :: Name -> Q Exp
+ TextShow.TH: makeShowbPrec :: Name -> Q Exp
+ TextShow.TH: makeShowbPrec1 :: Name -> Q Exp
+ TextShow.TH: makeShowbPrec2 :: Name -> Q Exp
+ TextShow.TH: makeShowbPrecWith :: Name -> Q Exp
+ TextShow.TH: makeShowbPrecWith2 :: Name -> Q Exp
+ TextShow.TH: makeShowt :: Name -> Q Exp
+ TextShow.TH: makeShowtList :: Name -> Q Exp
+ TextShow.TH: makeShowtPrec :: Name -> Q Exp
+ TextShow.TH: makeShowtl :: Name -> Q Exp
+ TextShow.TH: makeShowtlList :: Name -> Q Exp
+ TextShow.TH: makeShowtlPrec :: Name -> Q Exp
+ TextShow.Text.Read: instance TextShow Lexeme
+ TextShow.Text.Read: instance TextShow Number
+ TextShow.Text.Read: showbLexemePrec :: Int -> Lexeme -> Builder
+ TextShow.Text.Read: showbNumberPrec :: Int -> Number -> Builder
Files
- CHANGELOG.md +80/−0
- LICENSE +1/−1
- README.md +6/−11
- src/Text/Show/Text.hs +0/−57
- src/Text/Show/Text/Classes.hs +0/−378
- src/Text/Show/Text/Control/Applicative.hs +0/−50
- src/Text/Show/Text/Control/Concurrent.hs +0/−59
- src/Text/Show/Text/Control/Exception.hs +0/−299
- src/Text/Show/Text/Control/Monad/ST.hs +0/−42
- src/Text/Show/Text/Data/Array.hs +0/−81
- src/Text/Show/Text/Data/Bool.hs +0/−29
- src/Text/Show/Text/Data/ByteString.hs +0/−92
- src/Text/Show/Text/Data/Char.hs +0/−109
- src/Text/Show/Text/Data/Complex.hs +0/−65
- src/Text/Show/Text/Data/Data.hs +0/−78
- src/Text/Show/Text/Data/Dynamic.hs +0/−38
- src/Text/Show/Text/Data/Either.hs +0/−38
- src/Text/Show/Text/Data/Fixed.hs +0/−93
- src/Text/Show/Text/Data/Floating.hs +0/−413
- src/Text/Show/Text/Data/Functor/Identity.hs +0/−43
- src/Text/Show/Text/Data/Integral.hs +0/−241
- src/Text/Show/Text/Data/List.hs +0/−32
- src/Text/Show/Text/Data/Maybe.hs +0/−35
- src/Text/Show/Text/Data/Monoid.hs +0/−136
- src/Text/Show/Text/Data/OldTypeable.hs +0/−78
- src/Text/Show/Text/Data/Ord.hs +0/−63
- src/Text/Show/Text/Data/Proxy.hs +0/−40
- src/Text/Show/Text/Data/Ratio.hs +0/−70
- src/Text/Show/Text/Data/Text.hs +0/−156
- src/Text/Show/Text/Data/Tuple.hs +0/−231
- src/Text/Show/Text/Data/Type/Coercion.hs +0/−53
- src/Text/Show/Text/Data/Type/Equality.hs +0/−54
- src/Text/Show/Text/Data/Typeable.hs +0/−104
- src/Text/Show/Text/Data/Typeable/Utils.hs +0/−31
- src/Text/Show/Text/Data/Version.hs +0/−52
- src/Text/Show/Text/Data/Void.hs +0/−31
- src/Text/Show/Text/Debug/Trace.hs +0/−368
- src/Text/Show/Text/Debug/Trace/Generic.hs +0/−43
- src/Text/Show/Text/Debug/Trace/TH.hs +0/−46
- src/Text/Show/Text/Foreign/C/Types.hs +0/−479
- src/Text/Show/Text/Foreign/Ptr.hs +0/−117
- src/Text/Show/Text/Functions.hs +0/−41
- src/Text/Show/Text/GHC/Conc/Windows.hs +0/−42
- src/Text/Show/Text/GHC/Event.hs +0/−58
- src/Text/Show/Text/GHC/Fingerprint.hs +0/−53
- src/Text/Show/Text/GHC/Generics.hs +0/−201
- src/Text/Show/Text/GHC/RTS/Flags.hs +0/−267
- src/Text/Show/Text/GHC/StaticPtr.hs +0/−47
- src/Text/Show/Text/GHC/Stats.hs +0/−45
- src/Text/Show/Text/GHC/TypeLits.hs +0/−125
- src/Text/Show/Text/Generic.hs +0/−446
- src/Text/Show/Text/Instances.hs +0/−65
- src/Text/Show/Text/Numeric/Natural.hs +0/−53
- src/Text/Show/Text/System/Exit.hs +0/−32
- src/Text/Show/Text/System/IO.hs +0/−158
- src/Text/Show/Text/System/Posix/Types.hs +0/−394
- src/Text/Show/Text/TH.hs +0/−18
- src/Text/Show/Text/TH/Internal.hs +0/−1434
- src/Text/Show/Text/Text/Read.hs +0/−79
- src/Text/Show/Text/Utils.hs +0/−80
- src/TextShow.hs +67/−0
- src/TextShow/Classes.hs +377/−0
- src/TextShow/Control/Applicative.hs +49/−0
- src/TextShow/Control/Concurrent.hs +57/−0
- src/TextShow/Control/Exception.hs +299/−0
- src/TextShow/Control/Monad/ST.hs +41/−0
- src/TextShow/Data/Array.hs +81/−0
- src/TextShow/Data/Bool.hs +29/−0
- src/TextShow/Data/ByteString.hs +92/−0
- src/TextShow/Data/Char.hs +109/−0
- src/TextShow/Data/Complex.hs +64/−0
- src/TextShow/Data/Data.hs +76/−0
- src/TextShow/Data/Dynamic.hs +38/−0
- src/TextShow/Data/Either.hs +36/−0
- src/TextShow/Data/Fixed.hs +93/−0
- src/TextShow/Data/Floating.hs +411/−0
- src/TextShow/Data/Functor/Identity.hs +42/−0
- src/TextShow/Data/Integral.hs +241/−0
- src/TextShow/Data/List.hs +30/−0
- src/TextShow/Data/Maybe.hs +33/−0
- src/TextShow/Data/Monoid.hs +134/−0
- src/TextShow/Data/OldTypeable.hs +76/−0
- src/TextShow/Data/Ord.hs +59/−0
- src/TextShow/Data/Proxy.hs +38/−0
- src/TextShow/Data/Ratio.hs +68/−0
- src/TextShow/Data/Text.hs +155/−0
- src/TextShow/Data/Tuple.hs +229/−0
- src/TextShow/Data/Type/Coercion.hs +51/−0
- src/TextShow/Data/Type/Equality.hs +52/−0
- src/TextShow/Data/Typeable.hs +102/−0
- src/TextShow/Data/Typeable/Utils.hs +31/−0
- src/TextShow/Data/Version.hs +52/−0
- src/TextShow/Data/Void.hs +31/−0
- src/TextShow/Debug/Trace.hs +369/−0
- src/TextShow/Debug/Trace/Generic.hs +46/−0
- src/TextShow/Debug/Trace/TH.hs +46/−0
- src/TextShow/Foreign/C/Types.hs +477/−0
- src/TextShow/Foreign/Ptr.hs +115/−0
- src/TextShow/Functions.hs +40/−0
- src/TextShow/GHC/Conc/Windows.hs +42/−0
- src/TextShow/GHC/Event.hs +81/−0
- src/TextShow/GHC/Fingerprint.hs +51/−0
- src/TextShow/GHC/Generics.hs +199/−0
- src/TextShow/GHC/RTS/Flags.hs +265/−0
- src/TextShow/GHC/StaticPtr.hs +47/−0
- src/TextShow/GHC/Stats.hs +45/−0
- src/TextShow/GHC/TypeLits.hs +124/−0
- src/TextShow/Generic.hs +444/−0
- src/TextShow/Instances.hs +65/−0
- src/TextShow/Numeric/Natural.hs +51/−0
- src/TextShow/System/Exit.hs +32/−0
- src/TextShow/System/IO.hs +156/−0
- src/TextShow/System/Posix/Types.hs +392/−0
- src/TextShow/TH.hs +18/−0
- src/TextShow/TH/Internal.hs +1431/−0
- src/TextShow/Text/Read.hs +78/−0
- src/TextShow/Utils.hs +80/−0
- tests/Derived/DataFamilies.hs +11/−12
- tests/Derived/DatatypeContexts.hs +23/−24
- tests/Derived/ExistentialQuantification.hs +21/−22
- tests/Derived/Infix.hs +27/−28
- tests/Derived/MagicHash.hs +6/−7
- tests/Derived/PolyKinds.hs +158/−76
- tests/Derived/RankNTypes.hs +20/−21
- tests/Derived/Records.hs +15/−16
- tests/Derived/TypeSynonyms.hs +16/−17
- tests/Instances/FromStringTextShow.hs +1/−1
- tests/Instances/GHC/Event.hs +14/−1
- tests/Instances/Generic.hs +1/−1
- tests/Spec/BuilderSpec.hs +1/−1
- tests/Spec/Control/ApplicativeSpec.hs +6/−6
- tests/Spec/Control/ConcurrentSpec.hs +15/−5
- tests/Spec/Control/ExceptionSpec.hs +22/−22
- tests/Spec/Control/Monad/STSpec.hs +2/−2
- tests/Spec/Data/ArraySpec.hs +3/−3
- tests/Spec/Data/BoolSpec.hs +3/−3
- tests/Spec/Data/ByteStringSpec.hs +4/−4
- tests/Spec/Data/CharSpec.hs +6/−6
- tests/Spec/Data/ComplexSpec.hs +2/−2
- tests/Spec/Data/DataSpec.hs +6/−6
- tests/Spec/Data/DynamicSpec.hs +2/−2
- tests/Spec/Data/EitherSpec.hs +4/−4
- tests/Spec/Data/FixedSpec.hs +11/−11
- tests/Spec/Data/FloatingSpec.hs +11/−11
- tests/Spec/Data/Functor/IdentitySpec.hs +2/−2
- tests/Spec/Data/IntegralSpec.hs +14/−14
- tests/Spec/Data/ListSpec.hs +7/−7
- tests/Spec/Data/MaybeSpec.hs +4/−4
- tests/Spec/Data/MonoidSpec.hs +23/−23
- tests/Spec/Data/OldTypeableSpec.hs +3/−3
- tests/Spec/Data/OrdSpec.hs +4/−4
- tests/Spec/Data/ProxySpec.hs +3/−3
- tests/Spec/Data/RatioSpec.hs +2/−2
- tests/Spec/Data/TextSpec.hs +8/−8
- tests/Spec/Data/TupleSpec.hs +58/−58
- tests/Spec/Data/Type/CoercionSpec.hs +2/−2
- tests/Spec/Data/Type/EqualitySpec.hs +2/−2
- tests/Spec/Data/TypeableSpec.hs +3/−3
- tests/Spec/Data/VersionSpec.hs +5/−5
- tests/Spec/Derived/DataFamiliesSpec.hs +7/−7
- tests/Spec/Derived/DatatypeContextsSpec.hs +3/−3
- tests/Spec/Derived/ExistentialQuantificationSpec.hs +3/−3
- tests/Spec/Derived/InfixSpec.hs +14/−14
- tests/Spec/Derived/MagicHashSpec.hs +3/−3
- tests/Spec/Derived/PolyKindsSpec.hs +22/−14
- tests/Spec/Derived/RankNTypesSpec.hs +3/−3
- tests/Spec/Derived/RecordsSpec.hs +8/−8
- tests/Spec/Derived/TypeSynonymsSpec.hs +8/−8
- tests/Spec/Foreign/C/TypesSpec.hs +26/−26
- tests/Spec/Foreign/PtrSpec.hs +7/−7
- tests/Spec/FromStringTextShowSpec.hs +6/−6
- tests/Spec/FunctionsSpec.hs +4/−4
- tests/Spec/GHC/Conc/WindowsSpec.hs +2/−2
- tests/Spec/GHC/EventSpec.hs +10/−3
- tests/Spec/GHC/FingerprintSpec.hs +2/−2
- tests/Spec/GHC/GenericsSpec.hs +23/−23
- tests/Spec/GHC/RTS/FlagsSpec.hs +15/−15
- tests/Spec/GHC/StaticPtrSpec.hs +2/−2
- tests/Spec/GHC/StatsSpec.hs +2/−2
- tests/Spec/GHC/TypeLitsSpec.hs +10/−10
- tests/Spec/GenericSpec.hs +4/−4
- tests/Spec/Numeric/NaturalSpec.hs +2/−2
- tests/Spec/System/ExitSpec.hs +2/−2
- tests/Spec/System/IOSpec.hs +13/−13
- tests/Spec/System/Posix/TypesSpec.hs +15/−15
- tests/Spec/Text/ReadSpec.hs +3/−3
- tests/Spec/Utils.hs +36/−37
- tests/TransformersCompat.hs +25/−17
- text-show.cabal +70/−77
CHANGELOG.md view
@@ -1,3 +1,83 @@+# 2 +* Changed the top-level module name from `Text.Show.Text` to `TextShow`, since the former was extremely verbose without much benefit. As a result, this will break all existing code that depends on `text-show`. +* Several typeclasses and functions were renamed so as to not to clash with the `Prelude`: + * `Show` → `TextShow` + * `Show1` → `TextShow1` + * `Show2` → `TextShow2` + * `show` → `showt` + * `showLazy` → `showtl` + * `showPrec` → `showtPrec` + * `showPrecLazy` → `showtlPrec` + * `showList` → `showtList` + * `showListLazy` → `showtlList` + * `print` → `printT` + * `printLazy` → `printTL` + * `hPrint` → `hPrintT` + * `hPrintLazy` → `hPrintTL` + * `GShow` → `GTextShow` + * `GShow1` → `GTextShow1` + * `genericShow` → `genericShowt` + * `genericShowLazy` → `genericShowtl` + * `genericShowPrec` → `genericShowtPrec` + * `genericShowPrecLazy` → `genericShowtlPrec` + * `genericShowList` → `genericShowtList` + * `genericShowListLazy` → `genericShowtlList` + * `genericPrint` → `genericPrintT` + * `genericPrintLazy` → genericPrintTL`` + * `genericHPrint` → `genericHPrintT` + * `genericHPrintLazy` → `genericHPrintTL` + * `deriveShow` → `deriveTextShow` + * `deriveShow1` → `deriveTextShow1` + * `deriveShow2` → `deriveTextShow2` + * `mkShow` → `makeShowt` + * `mkShowLazy` → `makeShowtl` + * `mkShowPrec` → `makeShowtPrec` + * `mkShowPrecLazy` → `makeShowtlPrec` + * `mkShowList` → `makeShowtList` + * `mkShowListLazy` → `makeShowtlList` + * `mkShowb` → `makeShowb` + * `mkShowbPrec` → `makeShowbPrec` + * `mkShowbList` → `makeShowbList` + * `mkPrint` → `makePrintT` + * `mkPrintLazy` → `makePrintTL` + * `mkHPrint` → `makeHPrintT` + * `mkHPrintLazy` → `makeHPrintTL` + * `mkShowbPrecWith` → `makeShowbPrecWith` + * `mkShowbPrec1` → `makeShowbPrec1` + * `mkShowbPrecWith2` → `makeShowbPrecWith2` + * `mkShowbPrec2` → `makeShowbPrec2` + * `trace` → `tracet` + * `traceLazy` → `tracetl` + * `traceId` → `tracetId` + * `traceIdLazy` → `tracetlId` + * `traceShow` → `traceTextShow` + * `traceShowId` → `traceTextShowId` + * `traceStack` → `tracetStack` + * `traceStackLazy` → `tracetlStack` + * `traceIO` → `tracetIO` + * `traceIOLazy` → `tracetlIO` + * `traceM` → `tracetM` + * `traceMLazy` → `tracetlM` + * `traceShowM` → `traceTextShowM` + * `traceEvent` → `tracetEvent` + * `traceEventLazy` → `tracetlEvent` + * `traceEventIO` → `travetEventIO` + * `traceEventIOLazy` → `tracetlEventIO` + * `traceMarker` → `tracetMarker` + * `traceMarkerLazy` → `tracetlMarker` + * `traceMarkerIO` → `tracetMarkerIO` + * `traceMarkerIOLazy` → `tracetlMarkerIO` + * `genericTraceShow` → `genericTraceTextShow` + * `genericTraceShowId` → `genericTraceTextShowId` + * `genericTraceShowM` → `genericTraceTextShowM` + * `mkTraceShow` → `makeTraceTextShow` + * `mkTraceShowId` → `makeTraceTextShowId` + * `mkTraceShowM` → `makeTraceTextShowM` +* Added `TextShow Lifetime` instance in `TextShow.GHC.Event` (if using `base-4.8.1.0` or later) +* Generalized `tracetM`, `tracetlM`, and `traceTextShowM` to use an `Applicative` constraint instead of `Monad` +* Fixed a bug in which the `TextShow(1)` instances for `Proxy`, `(:~:)`, and `Coercion` didn't use `-XPolyKinds` +* Fixed a bug in the Template Haskell deriver which would cause `deriveTextShow` to fail on type parameters with sufficiently high kinds + # 1 * The `Show1` class has been completely overhauled. `Show1` now uses the function `showbPrecWith`, which takes as an argument a function of type `Int -> a -> Builder` to show occurrences of the type parameter (instead of requiring the type parameter to be a `Show` instance). This matches the new implementation of `Show1` in the next version of `transformers`. A similar `Show2` class (with the function `showbPrecWith2`) was also added. * As a consequence, `Show1` instances should no longer be defined in terms of `showbPrec`; rather, `Show` instances should be defined in terms of `showbPrecWith` or `showbPrecWith2`, and `Show1` instances can be defined in terms of `showbPrecWith2`.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2014, Ryan Scott +Copyright (c) 2014-2015, Ryan Scott All rights reserved.
README.md view
@@ -2,24 +2,19 @@ `text-show` offers a replacement for the `Show` typeclass intended for use with `Text` instead of `String`s. This package was created in the spirit of [`bytestring-show`](http://hackage.haskell.org/package/bytestring-show). -At the moment, `text-show` provides `Show` instances for most data types in the [`array`](http://hackage.haskell.org/package/array), [`base`](http://hackage.haskell.org/package/base), [`bytestring`](http://hackage.haskell.org/package/bytestring), and [`text`](http://hackage.haskell.org/package/text) packages. Therefore, much of the source code for `text-show` consists of borrowed code from those packages in order to ensure that the behaviors of the two `Show` typeclasses coincide. +At the moment, `text-show` provides instances for most data types in the [`array`](http://hackage.haskell.org/package/array), [`base`](http://hackage.haskell.org/package/base), [`bytestring`](http://hackage.haskell.org/package/bytestring), and [`text`](http://hackage.haskell.org/package/text) packages. Therefore, much of the source code for `text-show` consists of borrowed code from those packages in order to ensure that the behaviors of `Show` and `TextShow` coincide. -For most uses, simply importing `Text.Show.Text` will suffice: +For most uses, simply importing `TextShow` will suffice: ```haskell module Main where -import Data.Text (Text) -import Prelude hiding (Show(..), print) -import Text.Show.Text - -hello :: Text -hello = show (Just "Hello, World!") +import TextShow main :: IO () -main = print hello +main = printT (Just "Hello, World!") ``` -If you desire it, there are also monomorphic versions of the `showb` function available in the submodules of `Text.Show.Text`. A naming convention is present in which functions that show different values depending on the precedence end with `Prec`(e.g., `showbIntPrec`), whereas functions that show the same values regardless of precedence do not end with `Prec` (e.g., `showbBool`). +If you desire it, there are also monomorphic versions of the `showb` function available in the submodules of `Text.Show.Text`. See the [naming conventions](https://github.com/RyanGlScott/text-show/wiki/Naming-conventions) page for more information. -Support for automatically deriving `Show` instances can be found in the `Text.Show.Text.TH` and `Text.Show.Text.Generic` modules. If you don't know which one to use, use `Text.Show.Text.TH`. +Support for automatically deriving `TextShow` instances can be found in the `TextShow.TH` and `TextShow.Generic` modules. If you don't know which one to use, use `TextShow.TH`.
− src/Text/Show/Text.hs
@@ -1,57 +0,0 @@-{-| -Module: Text.Show.Text -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Efficiently convert from values to 'Text' via 'Builder's. - -/Since: 0.1/ --} -module Text.Show.Text ( - -- * The @Show@-related classes - -- ** 'Show' - Show(..) - , show - , showLazy - , showPrec - , showPrecLazy - , showList - , showListLazy - , showbParen - , showbSpace - -- ** 'Show1' - , Show1(..) - , showbPrec1 - , showbUnaryWith - -- ** 'Show2' - , Show2(..) - , showbPrec2 - , showbBinaryWith - -- * 'Builder's - , module Data.Text.Lazy.Builder - , toString - , toText - , lengthB - , unlinesB - , unwordsB - -- * Printing values - , print - , printLazy - , hPrint - , hPrintLazy - -- * Conversion between @String@ and @Text@ 'Show' - , FromStringShow(..) - , FromTextShow(..) - ) where - -import Data.Text.Lazy.Builder - -import Prelude () - -import Text.Show.Text.Classes -import Text.Show.Text.Instances () -import Text.Show.Text.Utils (toString, toText, lengthB, - unlinesB, unwordsB)
− src/Text/Show/Text/Classes.hs
@@ -1,378 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE DeriveFoldable #-} -{-# LANGUAGE DeriveFunctor #-} -{-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE OverloadedStrings #-} - -#if __GLASGOW_HASKELL__ >= 702 -{-# LANGUAGE DeriveGeneric #-} -#else -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -#endif - -#if __GLASGOW_HASKELL__ >= 708 -{-# LANGUAGE AutoDeriveTypeable #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE StandaloneDeriving #-} -#endif -{-| -Module: Text.Show.Text.Classes -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -The 'Show', 'Show1', and 'Show2' typeclasses. --} -module Text.Show.Text.Classes where - -import Data.Data (Data, Typeable) -import Data.Monoid.Compat ((<>)) -import Data.Text as TS (Text) -import qualified Data.Text.IO as TS (putStrLn, hPutStrLn) -import qualified Data.Text.Lazy as TL (Text) -import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn) -import Data.Text.Lazy (toStrict) -import Data.Text.Lazy.Builder (Builder, fromString, singleton, toLazyText) - -#if __GLASGOW_HASKELL__ >= 702 -import GHC.Generics (Generic) -# if __GLASGOW_HASKELL__ >= 706 -import GHC.Generics (Generic1) -# endif -#else -import qualified Generics.Deriving.TH as Generics (deriveAll) -#endif -import GHC.Show (appPrec, appPrec1) - -import Prelude () -import Prelude.Compat hiding (Show(..)) - -import System.IO (Handle) - -import Text.Read (Read(..), readListPrecDefault) -import qualified Text.Show as S (Show(..)) -import Text.Show.Text.Utils (toString) - -#include "inline.h" - -------------------------------------------------------------------------------- - --- | Conversion of values to @Text@. Because there are both strict and lazy @Text@ --- variants, the 'Show' class deliberately avoids using @Text@ in its functions. --- Instead, 'showbPrec', 'showb', and 'showbList' all return 'Builder', an --- efficient intermediate form that can be converted to either kind of @Text@. --- --- 'Builder' is a 'Monoid', so it is useful to use the 'mappend' (or '<>') function --- to combine 'Builder's when creating 'Show' instances. As an example: --- --- @ --- import Text.Show.Text --- --- data Example = Example Int Int --- instance Show Example where --- showb (Example i1 i2) = showb i1 <> showbSpace <> showb i2 --- @ --- --- If you do not want to create 'Show' instances manually, you can alternatively --- use the "Text.Show.Text.TH" module to automatically generate default 'Show' --- instances using Template Haskell, or the "Text.Show.Text.Generic" module to --- quickly define 'Show' instances using 'genericShowbPrec'. --- --- /Since: 0.1/ -class Show a where - -- | Convert a value to a 'Builder' with the given predence. - -- - -- /Since: 0.1/ - showbPrec :: Int -- ^ The operator precedence of the enclosing context (a number - -- from @0@ to @11@). Function application has precedence @10@. - -> a -- ^ The value to be converted to a 'String'. - -> Builder - - -- | A specialized variant of 'showbPrec' using precedence context zero. - -- - -- /Since: 0.1/ - showb :: a -> Builder - - -- | Allows for specialized display of lists. This is used, for example, when - -- showing lists of 'Char's. - -- - -- /Since: 0.1/ - showbList :: [a] -> Builder - - showbPrec _ = showb - - showb = showbPrec 0 - - showbList = showbListWith showb -#if __GLASGOW_HASKELL__ >= 708 - {-# MINIMAL showbPrec | showb #-} - -deriving instance Typeable Show -#endif - --- | Constructs a strict 'TS.Text' from a single value. --- --- /Since: 0.1/ -show :: Show a => a -> TS.Text -show = toStrict . showLazy -{-# INLINE show #-} - --- | Constructs a lazy 'TL.Text' from a single value. --- --- /Since: 0.3/ -showLazy :: Show a => a -> TL.Text -showLazy = toLazyText . showb -{-# INLINE showLazy #-} - --- | Constructs a strict 'TS.Text' from a single value with the given precedence. --- --- /Since: 0.3/ -showPrec :: Show a => Int -> a -> TS.Text -showPrec p = toStrict . showPrecLazy p -{-# INLINE showPrec #-} - --- | Constructs a lazy 'TL.Text' from a single value with the given precedence. --- --- /Since: 0.3/ -showPrecLazy :: Show a => Int -> a -> TL.Text -showPrecLazy p = toLazyText . showbPrec p -{-# INLINE showPrecLazy #-} - --- | Construct a strict 'TS.Text' from a list of values. --- --- /Since: 0.3.1/ -showList :: Show a => [a] -> TS.Text -showList = toStrict . showListLazy -{-# INLINE showList #-} - --- | Construct a lazy 'TL.Text' from a list of values. --- --- /Since: 0.3.1/ -showListLazy :: Show a => [a] -> TL.Text -showListLazy = toLazyText . showbList -{-# INLINE showListLazy #-} - --- | Surrounds 'Builder' output with parentheses if the 'Bool' parameter is 'True'. --- --- /Since: 0.1/ -showbParen :: Bool -> Builder -> Builder -showbParen p builder | p = singleton '(' <> builder <> singleton ')' - | otherwise = builder -{-# INLINE showbParen #-} - --- | Construct a 'Builder' containing a single space character. --- --- /Since: 0.5/ -showbSpace :: Builder -showbSpace = singleton ' ' - --- | Converts a list of values into a 'Builder' in which the values are surrounded --- by square brackets and each value is separated by a comma. The function argument --- controls how each element is shown. - --- @'showbListWith' 'showb'@ is the default implementation of 'showbList' save for --- a few special cases (e.g., 'String'). --- --- /Since: 0.7/ -showbListWith :: (a -> Builder) -> [a] -> Builder -showbListWith _ [] = "[]" -showbListWith showbx (x:xs) = singleton '[' <> showbx x <> go xs -- "[.. - where - go (y:ys) = singleton ',' <> showbx y <> go ys -- ..,.. - go [] = singleton ']' -- ..]" -{-# INLINE showbListWith #-} - --- | Writes a value's strict 'TS.Text' representation to the standard output, followed --- by a newline. --- --- /Since: 0.1/ -print :: Show a => a -> IO () -print = TS.putStrLn . show -{-# INLINE print #-} - --- | Writes a value's lazy 'TL.Text' representation to the standard output, followed --- by a newline. --- --- /Since: 0.3/ -printLazy :: Show a => a -> IO () -printLazy = TL.putStrLn . showLazy -{-# INLINE printLazy #-} - --- | Writes a value's strict 'TS.Text' representation to a file handle, followed --- by a newline. --- --- /Since: 0.3/ -hPrint :: Show a => Handle -> a -> IO () -hPrint h = TS.hPutStrLn h . show -{-# INLINE hPrint #-} - --- | Writes a value's lazy 'TL.Text' representation to a file handle, followed --- by a newline. --- --- /Since: 0.3/ -hPrintLazy :: Show a => Handle -> a -> IO () -hPrintLazy h = TL.hPutStrLn h . showLazy -{-# INLINE hPrintLazy #-} - -------------------------------------------------------------------------------- - --- | Lifting of the 'Show' class to unary type constructors. --- --- /Since: 1/ -class Show1 f where - -- | Lifts a 'showbPrec' function through the type constructor. - -- - -- /Since: 1/ - showbPrecWith :: (Int -> a -> Builder) -> Int -> f a -> Builder - -#if __GLASGOW_HASKELL__ >= 708 -deriving instance Typeable Show1 -#endif - --- | Lift the standard 'showbPrec' function through the type constructor. --- --- /Since: 1/ -showbPrec1 :: (Show1 f, Show a) => Int -> f a -> Builder -showbPrec1 = showbPrecWith showbPrec -{-# INLINE showbPrec1 #-} - --- | @'showbUnaryWith' sp n p x@ produces the 'Builder' representation of a unary data --- constructor with name @n@ and argument @x@, in precedence context @p@, using the --- function @sp@ to show occurrences of the type argument. --- --- /Since: 1/ -showbUnaryWith :: (Int -> a -> Builder) -> Builder -> Int -> a -> Builder -showbUnaryWith sp nameB p x = showbParen (p > appPrec) $ - nameB <> showbSpace <> sp appPrec1 x -{-# INLINE showbUnaryWith #-} - -------------------------------------------------------------------------------- - --- | Lifting of the 'Show' class to binary type constructors. --- --- /Since: 1/ -class Show2 f where - -- | Lifts 'showbPrec' functions through the type constructor. - -- - -- /Since: 1/ - showbPrecWith2 :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> - Int -> f a b -> Builder - -#if __GLASGOW_HASKELL__ >= 708 -deriving instance Typeable Show2 -#endif - --- | Lift two 'showbPrec' functions through the type constructor. --- --- /Since: 1/ -showbPrec2 :: (Show2 f, Show a, Show b) => Int -> f a b -> Builder -showbPrec2 = showbPrecWith2 showbPrec showbPrec -{-# INLINE showbPrec2 #-} - --- | @'showbBinaryWith' sp n p x y@ produces the 'Builder' representation of a binary --- data constructor with name @n@ and arguments @x@ and @y@, in precedence context --- @p@, using the functions @sp1@ and @sp2@ to show occurrences of the type arguments. --- --- /Since: 1/ -showbBinaryWith :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> - Builder -> Int -> a -> b -> Builder -showbBinaryWith sp1 sp2 nameB p x y = showbParen (p > appPrec) $ nameB - <> showbSpace <> sp1 appPrec1 x - <> showbSpace <> sp2 appPrec1 y -{-# INLINE showbBinaryWith #-} - -------------------------------------------------------------------------------- - --- | The @Text@ 'T.Show' instance for 'FromStringShow' is based on its @String@ --- 'S.Show' instance. That is, --- --- @ --- showbPrec p ('FromStringShow' x) = 'fromString' (showsPrec p x "") --- @ --- --- /Since: 0.5/ -newtype FromStringShow a = FromStringShow { fromStringShow :: a } - deriving ( Data - , Eq - , Foldable - , Functor -#if __GLASGOW_HASKELL__ >= 702 - , Generic -# if __GLASGOW_HASKELL__ >= 706 - , Generic1 -# endif -#endif - , Ord - , Traversable - , Typeable - ) - -instance Read a => Read (FromStringShow a) where - readPrec = FromStringShow <$> readPrec - INLINE_INST_FUN(readPrec) - - readListPrec = readListPrecDefault - INLINE_INST_FUN(readListPrec) - -instance S.Show a => Show (FromStringShow a) where - showbPrec p (FromStringShow x) = fromString $ S.showsPrec p x "" - INLINE_INST_FUN(showbPrec) - -instance S.Show a => S.Show (FromStringShow a) where - showsPrec p (FromStringShow x) = S.showsPrec p x - INLINE_INST_FUN(showsPrec) - --- | The @String@ 'S.Show' instance for 'FromTextShow' is based on its @Text@ --- 'T.Show' instance. That is, --- --- @ --- showsPrec p ('FromTextShow' x) str = 'toString' (showbPrec p x) ++ str --- @ --- --- /Since: 0.6/ -newtype FromTextShow a = FromTextShow { fromTextShow :: a } - deriving ( Data - , Eq - , Foldable - , Functor -#if __GLASGOW_HASKELL__ >= 702 - , Generic -# if __GLASGOW_HASKELL__ >= 706 - , Generic1 -# endif -#endif - , Ord - , Traversable - , Typeable - ) - -instance Read a => Read (FromTextShow a) where - readPrec = FromTextShow <$> readPrec - INLINE_INST_FUN(readPrec) - - readListPrec = readListPrecDefault - INLINE_INST_FUN(readListPrec) - -instance Show a => S.Show (FromTextShow a) where - showsPrec p (FromTextShow x) = showString . toString $ showbPrec p x - INLINE_INST_FUN(showsPrec) - -instance Show a => Show (FromTextShow a) where - showbPrec = showbPrec1 - INLINE_INST_FUN(showbPrec) - -instance Show1 FromTextShow where - showbPrecWith sp p (FromTextShow x) = sp p x - INLINE_INST_FUN(showbPrecWith) - -------------------------------------------------------------------------------- - -#if __GLASGOW_HASKELL__ < 702 -$(Generics.deriveAll ''FromStringShow) -$(Generics.deriveAll ''FromTextShow) -#endif
− src/Text/Show/Text/Control/Applicative.hs
@@ -1,50 +0,0 @@-{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Control.Applicative -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'ZipList'. - -/Since: 0.3/ --} -module Text.Show.Text.Control.Applicative (showbConstPrecWith, showbZipListPrecWith) where - -import Control.Applicative (Const(..), ZipList) - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec), Show1(..), Show2(..), showbUnaryWith) -import Text.Show.Text.Data.List () -import Text.Show.Text.TH.Internal (deriveShow, deriveShow1) - --- | Convert a 'Const' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbConstPrecWith :: (Int -> a -> Builder) -> Int -> Const a b -> Builder -showbConstPrecWith sp = showbPrecWith2 sp undefined - --- | Convert a 'ZipList' to a 'Builder' with the given show function precedence. --- --- /Since: 1/ -showbZipListPrecWith :: (Int -> a -> Builder) -> Int -> ZipList a -> Builder -showbZipListPrecWith = showbPrecWith - -instance Show a => Show (Const a b) where - showbPrec = showbPrecWith undefined - -instance Show a => Show1 (Const a) where - showbPrecWith = showbPrecWith2 showbPrec - -instance Show2 Const where - showbPrecWith2 sp1 _ p (Const x) = showbUnaryWith sp1 "Const" p x - -$(deriveShow ''ZipList) -$(deriveShow1 ''ZipList)
− src/Text/Show/Text/Control/Concurrent.hs
@@ -1,59 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Control.Concurrent -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for concurrency-related data types. - -/Since: 0.3/ --} -module Text.Show.Text.Control.Concurrent ( - showbThreadIdPrec - , showbThreadStatusPrec - , showbBlockReason - ) where - -import Data.Text.Lazy.Builder (Builder) - -import GHC.Conc (BlockReason, ThreadId, ThreadStatus) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), FromStringShow(..)) -import Text.Show.Text.TH.Internal (deriveShow) - -#include "inline.h" - --- | Convert a 'ThreadId' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbThreadIdPrec :: Int -> ThreadId -> Builder -showbThreadIdPrec p = showbPrec p . FromStringShow -{-# INLINE showbThreadIdPrec #-} - --- | Convert a 'ThreadStatus' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbThreadStatusPrec :: Int -> ThreadStatus -> Builder -showbThreadStatusPrec = showbPrec -{-# INLINE showbThreadStatusPrec #-} - --- | Convert a 'BlockReason' to a 'Builder'. --- --- /Since: 0.3/ -showbBlockReason :: BlockReason -> Builder -showbBlockReason = showb -{-# INLINE showbBlockReason #-} - -instance Show ThreadId where - showbPrec = showbThreadIdPrec - INLINE_INST_FUN(showbPrec) - -$(deriveShow ''ThreadStatus) -$(deriveShow ''BlockReason)
− src/Text/Show/Text/Control/Exception.hs
@@ -1,299 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Control.Exception -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for 'Exception's. - -/Since: 0.3/ --} -module Text.Show.Text.Control.Exception ( - showbSomeExceptionPrec - , showbIOException - , showbArithException - , showbArrayException - , showbAssertionFailed -#if MIN_VERSION_base(4,7,0) - , showbSomeAsyncException -#endif - , showbAsyncException - , showbNonTermination - , showbNestedAtomically - , showbBlockedIndefinitelyOnMVar - , showbBlockedIndefinitelyOnSTM -#if MIN_VERSION_base(4,8,0) - , showbAllocationLimitExceeded -#endif - , showbDeadlock - , showbNoMethodError - , showbPatternMatchFail - , showbRecConError - , showbRecSelError - , showbRecUpdError - , showbErrorCall - , showbMaskingState - ) where - -import Control.Exception.Base - -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, fromString) - -import Prelude () -import Prelude.Compat hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), FromStringShow(..)) -import Text.Show.Text.TH.Internal (deriveShow) - -#include "inline.h" - --- | Convert a 'SomeException' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbSomeExceptionPrec :: Int -> SomeException -> Builder -showbSomeExceptionPrec p (SomeException e) = showbPrec p $ FromStringShow e -{-# INLINE showbSomeExceptionPrec #-} - --- | Convert an 'IOException' to a 'Builder'. --- --- /Since: 0.3/ -showbIOException :: IOException -> Builder -showbIOException = showb . FromStringShow -{-# INLINE showbIOException #-} - --- | Convert an 'ArithException' to a 'Builder'. --- --- /Since: 0.3/ -showbArithException :: ArithException -> Builder -showbArithException Overflow = "arithmetic overflow" -showbArithException Underflow = "arithmetic underflow" -showbArithException LossOfPrecision = "loss of precision" -showbArithException DivideByZero = "divide by zero" -showbArithException Denormal = "denormal" -#if MIN_VERSION_base(4,6,0) -showbArithException RatioZeroDenominator = "Ratio has zero denominator" -#endif - --- | Convert an 'ArrayException' to a 'Builder'. --- --- /Since: 0.3/ -showbArrayException :: ArrayException -> Builder -showbArrayException (IndexOutOfBounds s) - = "array index out of range" - <> (if not $ null s then ": " <> fromString s - else mempty) -showbArrayException (UndefinedElement s) - = "undefined array element" - <> (if not $ null s then ": " <> fromString s - else mempty) -{-# INLINE showbArrayException #-} - --- | Convert an 'AssertionFailed' exception to a 'Builder'. --- --- /Since: 0.3/ -showbAssertionFailed :: AssertionFailed -> Builder -showbAssertionFailed (AssertionFailed err) = fromString err -{-# INLINE showbAssertionFailed #-} - -#if MIN_VERSION_base(4,7,0) --- | Convert a 'SomeAsyncException' value to a 'Builder'. --- This function is only available with @base-4.7.0.0@ or later. --- --- /Since: 0.3/ -showbSomeAsyncException :: SomeAsyncException -> Builder -showbSomeAsyncException (SomeAsyncException e) = showb $ FromStringShow e -{-# INLINE showbSomeAsyncException #-} -#endif - --- | Convert an 'AsyncException' to a 'Builder'. --- --- /Since: 0.3/ -showbAsyncException :: AsyncException -> Builder -showbAsyncException StackOverflow = "stack overflow" -showbAsyncException HeapOverflow = "heap overflow" -showbAsyncException ThreadKilled = "thread killed" -showbAsyncException UserInterrupt = "user interrupt" -{-# INLINE showbAsyncException #-} - --- | Convert a 'NonTermination' exception to a 'Builder'. --- --- /Since: 0.3/ -showbNonTermination :: NonTermination -> Builder -showbNonTermination NonTermination = "<<loop>>" -{-# INLINE showbNonTermination #-} - --- | Convert a 'NestedAtomically' exception to a 'Builder'. --- --- /Since: 0.3/ -showbNestedAtomically :: NestedAtomically -> Builder -showbNestedAtomically NestedAtomically = "Control.Concurrent.STM.atomically was nested" -{-# INLINE showbNestedAtomically #-} - --- | Convert a 'BlockedIndefinitelyOnMVar' exception to a 'Builder'. --- --- /Since: 0.3/ -showbBlockedIndefinitelyOnMVar :: BlockedIndefinitelyOnMVar -> Builder -showbBlockedIndefinitelyOnMVar BlockedIndefinitelyOnMVar = "thread blocked indefinitely in an MVar operation" -{-# INLINE showbBlockedIndefinitelyOnMVar #-} - --- | Convert a 'BlockedIndefinitelyOnSTM' exception to a 'Builder'. --- --- /Since: 0.3/ -showbBlockedIndefinitelyOnSTM :: BlockedIndefinitelyOnSTM -> Builder -showbBlockedIndefinitelyOnSTM BlockedIndefinitelyOnSTM = "thread blocked indefinitely in an STM transaction" -{-# INLINE showbBlockedIndefinitelyOnSTM #-} - -#if MIN_VERSION_base(4,8,0) --- | Convert an 'AllocationLimitExceeded' exception to a 'Builder'. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbAllocationLimitExceeded :: AllocationLimitExceeded -> Builder -showbAllocationLimitExceeded AllocationLimitExceeded = "allocation limit exceeded" -{-# INLINE showbAllocationLimitExceeded #-} -#endif - --- | Convert a 'Deadlock' exception to a 'Builder'. --- --- /Since: 0.3/ -showbDeadlock :: Deadlock -> Builder -showbDeadlock Deadlock = "<<deadlock>>" -{-# INLINE showbDeadlock #-} - --- | Convert a 'NoMethodError' to a 'Builder'. --- --- /Since: 0.3/ -showbNoMethodError :: NoMethodError -> Builder -showbNoMethodError (NoMethodError err) = fromString err -{-# INLINE showbNoMethodError #-} - --- | Convert a 'PatternMatchFail' to a 'Builder'. --- --- /Since: 0.3/ -showbPatternMatchFail :: PatternMatchFail -> Builder -showbPatternMatchFail (PatternMatchFail err) = fromString err -{-# INLINE showbPatternMatchFail #-} - --- | Convert a 'RecConError' to a 'Builder'. --- --- /Since: 0.3/ -showbRecConError :: RecConError -> Builder -showbRecConError (RecConError err) = fromString err -{-# INLINE showbRecConError #-} - --- | Convert a 'RecSelError' to a 'Builder'. --- --- /Since: 0.3/ -showbRecSelError :: RecSelError -> Builder -showbRecSelError (RecSelError err) = fromString err -{-# INLINE showbRecSelError #-} - --- | Convert a 'RecUpdError' to a 'Builder'. --- --- /Since: 0.3/ -showbRecUpdError :: RecUpdError -> Builder -showbRecUpdError (RecUpdError err) = fromString err -{-# INLINE showbRecUpdError #-} - --- | Convert an 'ErrorCall' to a 'Builder'. --- --- /Since: 0.3/ -showbErrorCall :: ErrorCall -> Builder -showbErrorCall (ErrorCall err) = fromString err -{-# INLINE showbErrorCall #-} - --- | Convert a 'MaskingState' to a 'Builder'. --- --- /Since: 0.4/ -showbMaskingState :: MaskingState -> Builder -showbMaskingState = showb -{-# INLINE showbMaskingState #-} - -instance Show SomeException where - showbPrec = showbSomeExceptionPrec - INLINE_INST_FUN(showbPrec) - -instance Show IOException where - showb = showbIOException - INLINE_INST_FUN(showb) - -instance Show ArithException where - showb = showbArithException - INLINE_INST_FUN(showb) - -instance Show ArrayException where - showb = showbArrayException - INLINE_INST_FUN(showb) - -instance Show AssertionFailed where - showb = showbAssertionFailed - INLINE_INST_FUN(showb) - -#if MIN_VERSION_base(4,7,0) -instance Show SomeAsyncException where - showb = showbSomeAsyncException - {-# INLINE showb #-} -#endif - -instance Show AsyncException where - showb = showbAsyncException - INLINE_INST_FUN(showb) - -instance Show NonTermination where - showb = showbNonTermination - INLINE_INST_FUN(showb) - -instance Show NestedAtomically where - showb = showbNestedAtomically - INLINE_INST_FUN(showb) - -instance Show BlockedIndefinitelyOnMVar where - showb = showbBlockedIndefinitelyOnMVar - INLINE_INST_FUN(showb) - -instance Show BlockedIndefinitelyOnSTM where - showb = showbBlockedIndefinitelyOnSTM - INLINE_INST_FUN(showb) - -#if MIN_VERSION_base(4,8,0) -instance Show AllocationLimitExceeded where - showb = showbAllocationLimitExceeded - {-# INLINE showb #-} -#endif - -instance Show Deadlock where - showb = showbDeadlock - INLINE_INST_FUN(showb) - -instance Show NoMethodError where - showb = showbNoMethodError - INLINE_INST_FUN(showb) - -instance Show PatternMatchFail where - showb = showbPatternMatchFail - INLINE_INST_FUN(showb) - -instance Show RecConError where - showb = showbRecConError - INLINE_INST_FUN(showb) - -instance Show RecSelError where - showb = showbRecSelError - INLINE_INST_FUN(showb) - -instance Show RecUpdError where - showb = showbRecUpdError - INLINE_INST_FUN(showb) - -instance Show ErrorCall where - showb = showbErrorCall - INLINE_INST_FUN(showb) - -$(deriveShow ''MaskingState)
− src/Text/Show/Text/Control/Monad/ST.hs
@@ -1,42 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Control.Monad.ST -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for strict 'ST' values. - -/Since: 0.3/ --} -module Text.Show.Text.Control.Monad.ST (showbST) where - -import Control.Monad.ST (ST) -import Data.Text.Lazy.Builder (Builder) -import Prelude hiding (Show) -import Text.Show.Text.Classes (Show(showb), Show1(..), Show2(..)) - -#include "inline.h" - --- | Convert a strict 'ST' value to a 'Builder'. --- --- /Since: 0.3/ -showbST :: ST s a -> Builder -showbST = showb -{-# INLINE showbST #-} - -instance Show (ST s a) where - showb = showbPrecWith undefined 0 - INLINE_INST_FUN(showb) - -instance Show1 (ST s) where - showbPrecWith = showbPrecWith2 undefined - INLINE_INST_FUN(showbPrecWith) - -instance Show2 ST where - showbPrecWith2 _ _ _ _ = "<<ST action>>" - INLINE_INST_FUN(showbPrecWith2)
− src/Text/Show/Text/Data/Array.hs
@@ -1,81 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Array -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Array' values. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Array ( - showbArrayPrec - , showbUArrayPrec - , showbIArrayPrec - ) where - -import qualified Data.Array as Array (assocs, bounds) -import Data.Array (Array) -import qualified Data.Array.Base as IArray (assocs, bounds) -import Data.Array.Base (IArray) -import Data.Array.Unboxed (UArray) -import Data.Ix (Ix) -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder) - -import GHC.Show (appPrec) - -import Prelude () -import Prelude.Compat hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), showbParen, showbSpace) -import Text.Show.Text.Data.List () -import Text.Show.Text.Data.Tuple () - -#include "inline.h" - --- | Convert an 'Array' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbArrayPrec :: (Show i, Show e, Ix i) => Int -> Array i e -> Builder -showbArrayPrec p a = showbParen (p > appPrec) $ - "array " - <> showb (Array.bounds a) - <> showbSpace - <> showb (Array.assocs a) -{-# INLINE showbArrayPrec #-} - --- | Convert a 'UArray' value to a 'Builder' with the given precedence. --- --- /Since: 0.7/ -showbUArrayPrec :: (IArray UArray e, Ix i, Show i, Show e) => Int -> UArray i e -> Builder -showbUArrayPrec = showbIArrayPrec -{-# INLINE showbUArrayPrec #-} - -{-# SPECIALIZE - showbIArrayPrec :: (IArray UArray e, Ix i, Show i, Show e) => - Int -> UArray i e -> Builder - #-} --- | Convert an 'IArray' instance to a 'Builder' with the given precedence. --- --- /Since: 0.7/ -showbIArrayPrec :: (IArray a e, Ix i, Show i, Show e) => Int -> a i e -> Builder -showbIArrayPrec p a = showbParen (p > 9) $ - "array " - <> showb (IArray.bounds a) - <> showbSpace - <> showb (IArray.assocs a) - -instance (Show i, Show e, Ix i) => Show (Array i e) where - showbPrec = showbArrayPrec - INLINE_INST_FUN(showbPrec) - -instance (IArray UArray e, Ix i, Show i, Show e) => Show (UArray i e) where - showbPrec = showbUArrayPrec - INLINE_INST_FUN(showbPrec)
− src/Text/Show/Text/Data/Bool.hs
@@ -1,29 +0,0 @@-{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Bool -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Bool' values. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Bool (showbBool) where - -import Data.Text.Lazy.Builder (Builder) - -import Text.Show.Text.Classes (showb) -import Text.Show.Text.TH.Internal (deriveShow) - --- | Convert a 'Bool' to a 'Builder'. --- --- /Since: 0.3/ -showbBool :: Bool -> Builder -showbBool = showb -{-# INLINE showbBool #-} - -$(deriveShow ''Bool)
− src/Text/Show/Text/Data/ByteString.hs
@@ -1,92 +0,0 @@-{-# LANGUAGE CPP #-} -#if !(MIN_VERSION_bytestring(0,10,0)) -{-# LANGUAGE TemplateHaskell #-} -#endif -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.ByteString -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the @bytestring@ library. - -/Since: 0.3/ --} -module Text.Show.Text.Data.ByteString ( - showbByteStringStrict - , showbByteStringLazy - , showbByteStringLazyPrec - , showbShortByteString - ) where - -import qualified Data.ByteString as BS -import qualified Data.ByteString.Lazy as BL -import Data.ByteString.Short (ShortByteString) -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show(show)) - -import Text.Show.Text.Classes (Show(showb, showbPrec), FromStringShow(..)) - -#if !(MIN_VERSION_bytestring(0,10,0)) -import Text.Show.Text.TH.Internal (deriveShow) -#endif - -#include "inline.h" - --- | Convert a strict 'BS.ByteString' to a 'Builder'. --- --- /Since: 0.3/ -showbByteStringStrict :: BS.ByteString -> Builder -showbByteStringStrict = showb . FromStringShow -{-# INLINE showbByteStringStrict #-} - --- | Convert a lazy 'BL.ByteString' to a 'Builder'. --- --- /Since: 0.3/ -showbByteStringLazy :: BL.ByteString -> Builder -showbByteStringLazy = showbByteStringLazyPrec 0 -{-# INLINE showbByteStringLazy #-} - --- | Convert a lazy 'BL.ByteString' to a 'Builder' with the given precedence. --- --- With @bytestring-0.10.0.0@ or later, this function ignores the precedence --- argument, since lazy 'BL.ByteString's are printed out identically to 'String's. --- On earlier versions of @bytestring@, however, lazy 'BL.ByteString's can be printed --- with parentheses (e.g., @Chunk "example" Empty@ vs. @(Chunk "example" Empty)@) --- depending on the precedence. --- --- /Since: 0.3/ -showbByteStringLazyPrec :: Int -> BL.ByteString -> Builder -#if MIN_VERSION_bytestring(0,10,0) -showbByteStringLazyPrec _ = showb . FromStringShow -#else -showbByteStringLazyPrec = showbPrec -#endif -{-# INLINE showbByteStringLazyPrec #-} - --- | Convert a 'ShortByteString' to a 'Builder'. --- --- /Since: 0.7/ -showbShortByteString :: ShortByteString -> Builder -showbShortByteString = showb . FromStringShow -{-# INLINE showbShortByteString #-} - -instance Show BS.ByteString where - showb = showbByteStringStrict - INLINE_INST_FUN(showb) - -#if MIN_VERSION_bytestring(0,10,0) -instance Show BL.ByteString where - showbPrec = showbByteStringLazyPrec - INLINE_INST_FUN(showbPrec) -#else -$(deriveShow ''BL.ByteString) -#endif - -instance Show ShortByteString where - showb = showbShortByteString - INLINE_INST_FUN(showb)
− src/Text/Show/Text/Data/Char.hs
@@ -1,109 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Char -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for 'Char' and 'String'. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Char ( - showbChar - , showbLitChar - , showbString - , showbLitString - , showbGeneralCategory - , asciiTabB - ) where - -import Data.Array (Array, (!), listArray) -import Data.Char (GeneralCategory, isDigit, ord) -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, singleton) - -import Prelude () -import Prelude.Compat hiding (Show) - -import Text.Show.Text.Classes (Show(..)) -import Text.Show.Text.Data.Integral (showbIntPrec) -import Text.Show.Text.TH.Internal (deriveShow) - -#include "inline.h" - --- | A table of ASCII control characters that needs to be escaped with a backslash. --- --- /Since: 0.5/ -asciiTabB :: Array Int Builder -asciiTabB = listArray (0, 32) ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", - "BS" , "HT" , "LF" , "VT" , "FF" , "CR" , "SO" , "SI" , - "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", - "CAN", "EM" , "SUB", "ESC", "FS" , "GS" , "RS" , "US" , - "SP"] - --- | Convert a 'Char' to a 'Builder' (surrounded by single quotes). --- --- /Since: 0.3/ -showbChar :: Char -> Builder -showbChar '\'' = "'\\''" -showbChar c = singleton '\'' <> showbLitChar c <> singleton '\'' -{-# INLINE showbChar #-} - --- | Convert a 'Char' to a 'Builder' (without single quotes). --- --- /Since: 0.3/ -showbLitChar :: Char -> Builder -showbLitChar c | c > '\DEL' = singleton '\\' <> showbIntPrec 0 (ord c) -showbLitChar '\DEL' = "\\DEL" -showbLitChar '\\' = "\\\\" -showbLitChar c | c >= ' ' = singleton c -showbLitChar '\a' = "\\a" -showbLitChar '\b' = "\\b" -showbLitChar '\f' = "\\f" -showbLitChar '\n' = "\\n" -showbLitChar '\r' = "\\r" -showbLitChar '\t' = "\\t" -showbLitChar '\v' = "\\v" -showbLitChar '\SO' = "\\SO" -showbLitChar c = singleton '\\' <> (asciiTabB ! ord c) - --- | Convert a 'String' to a 'Builder' (surrounded by double quotes). --- --- /Since: 0.3/ -showbString :: String -> Builder -showbString cs = singleton '"' <> showbLitString cs <> singleton '"' -{-# INLINE showbString #-} - --- | Convert a 'String' to a 'Builder' (without double quotes). --- --- /Since: 0.3/ -showbLitString :: String -> Builder -showbLitString [] = mempty -showbLitString ('\SO':'H':cs) = "\\SO\\&H" <> showbLitString cs -showbLitString ('"':cs) = "\\\"" <> showbLitString cs -showbLitString (c:d:cs) - | c > '\DEL' && isDigit d = singleton '\\' <> showbIntPrec 0 (ord c) <> "\\&" - <> singleton d <> showbLitString cs -showbLitString (c:cs) = showbLitChar c <> showbLitString cs - --- | Convert a 'GeneralCategory' to a 'Builder'. --- --- /Since: 0.3/ -showbGeneralCategory :: GeneralCategory -> Builder -showbGeneralCategory = showb -{-# INLINE showbGeneralCategory #-} - -instance Show Char where - showb = showbChar - INLINE_INST_FUN(showb) - - showbList = showbString - INLINE_INST_FUN(showbList) - -$(deriveShow ''GeneralCategory)
− src/Text/Show/Text/Data/Complex.hs
@@ -1,65 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Ratio -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Ratio' values. - -Due to use of the @DatatypeContexts@ extension, there is no @Show1 Complex@ -instance on @base-4.3.0.0@. - -/Since: 0.5/ --} -module Text.Show.Text.Data.Complex (showbComplexPrec) where - -import Data.Complex (Complex) -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec)) -import Text.Show.Text.Data.Floating () -import Text.Show.Text.TH.Internal (mkShowbPrec) -#if MIN_VERSION_base(4,4,0) -import Text.Show.Text.TH.Internal (deriveShow1) -#endif - -#include "inline.h" - --- | Convert a 'Complex' value to a 'Builder' with the given precedence. --- --- Note that on @base-4.3.0.0@, this function must have a @('Show' a, 'RealFloat' a)@ --- constraint instead of just a @('Show' a)@ constraint. --- /Since: 0.5/ -#if MIN_VERSION_base(4,4,0) -showbComplexPrec :: Show a -#else -showbComplexPrec :: (RealFloat a, Show a) -#endif - => Int - -> Complex a - -> Builder -showbComplexPrec = showbPrec -{-# INLINE showbComplexPrec #-} - -instance -#if MIN_VERSION_base(4,4,0) - Show a -#else - (RealFloat a, Show a) -#endif - => Show (Complex a) where - {-# SPECIALIZE instance Show (Complex Float) #-} - {-# SPECIALIZE instance Show (Complex Double) #-} - showbPrec = $(mkShowbPrec ''Complex) - INLINE_INST_FUN(showbPrec) - -#if MIN_VERSION_base(4,4,0) -$(deriveShow1 ''Complex) -#endif
− src/Text/Show/Text/Data/Data.hs
@@ -1,78 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Data -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the @Data.Data@ module. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Data ( - showbConstr - , showbConstrRepPrec - , showbDataRepPrec - , showbDataTypePrec - , showbFixity - ) where - -import Data.Data (Constr, ConstrRep, DataRep, DataType, Fixity, showConstr) -import Data.Text.Lazy.Builder (Builder, fromString) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec)) -import Text.Show.Text.Data.List () -import Text.Show.Text.Data.Ratio () -import Text.Show.Text.TH.Internal (deriveShow) - -#include "inline.h" - --- | Convert a 'DataType' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbDataTypePrec :: Int -> DataType -> Builder -showbDataTypePrec = showbPrec -{-# INLINE showbDataTypePrec #-} - --- | Convert a 'DataRep' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbDataRepPrec :: Int -> DataRep -> Builder -showbDataRepPrec = showbPrec -{-# INLINE showbDataRepPrec #-} - --- | Convert a 'Constr' to a 'Builder'. --- --- /Since: 0.3/ -showbConstr :: Constr -> Builder -showbConstr = fromString . showConstr -{-# INLINE showbConstr #-} - --- | Convert a 'Fixity' value to a 'Builder'. --- --- /Since: 0.3/ -showbFixity :: Fixity -> Builder -showbFixity = showb -{-# INLINE showbFixity #-} - --- | Convert a 'ConstrRep' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbConstrRepPrec :: Int -> ConstrRep -> Builder -showbConstrRepPrec = showbPrec -{-# INLINE showbConstrRepPrec #-} - -$(deriveShow ''DataType) -$(deriveShow ''DataRep) -$(deriveShow ''ConstrRep) -$(deriveShow ''Fixity) - -instance Show Constr where - showb = showbConstr - INLINE_INST_FUN(showb)
− src/Text/Show/Text/Data/Dynamic.hs
@@ -1,38 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Dynamic -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Dynamic'. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Dynamic (showbDynamic) where - -import Data.Dynamic (Dynamic, dynTypeRep) -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder) - -import Prelude () - -import Text.Show.Text.Classes (Show(showb)) -import Text.Show.Text.Data.Typeable (showbTypeRepPrec) - -#include "inline.h" - --- | Convert a 'Dynamic' value to a 'Builder'. --- --- /Since: 0.3/ -showbDynamic :: Dynamic -> Builder -showbDynamic dyn = "<<" <> showbTypeRepPrec 0 (dynTypeRep dyn) <> ">>" -{-# INLINE showbDynamic #-} - -instance Show Dynamic where - showb = showbDynamic - INLINE_INST_FUN(showb)
− src/Text/Show/Text/Data/Either.hs
@@ -1,38 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Either -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Either' values. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Either (showbEitherPrecWith2) where - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (showbPrecWith2) -import Text.Show.Text.TH.Internal (deriveShow, deriveShow1, deriveShow2) - -#include "inline.h" - --- | Convert a 'Either' value to a 'Builder' with the given show functions --- and precedence. --- --- /Since: 1/ -showbEitherPrecWith2 :: (Int -> a -> Builder) -> (Int -> b -> Builder) - -> Int -> Either a b -> Builder -showbEitherPrecWith2 = showbPrecWith2 -{-# INLINE showbEitherPrecWith2 #-} - -$(deriveShow ''Either) -$(deriveShow1 ''Either) -$(deriveShow2 ''Either)
− src/Text/Show/Text/Data/Fixed.hs
@@ -1,93 +0,0 @@-{-# LANGUAGE CPP #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Fixed -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Fixed' values. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Fixed (showbFixed) where - -import Data.Fixed (HasResolution(..)) -import Data.Text.Lazy.Builder (Builder) - -import Prelude () -import Prelude.Compat hiding (Show) - -import Text.Show.Text.Classes (Show(showb)) - -#if MIN_VERSION_base(4,7,0) -import Data.Fixed (Fixed(..)) -import Data.Int (Int64) -import Data.Monoid.Compat ((<>)) -import Data.Semigroup (timesN) -import Data.Text.Lazy.Builder (singleton) - -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Utils (lengthB) -#else -import Data.Fixed (Fixed, showFixed) -import Data.Text.Lazy.Builder (fromString) -#endif - -#include "inline.h" - --- | Convert a 'Fixed' value to a 'Builder', where the first argument indicates --- whether to chop off trailing zeroes. --- --- /Since: 0.3/ -showbFixed :: HasResolution a => Bool -> Fixed a -> Builder -#if MIN_VERSION_base(4,7,0) -showbFixed chopTrailingZeroes fa@(MkFixed a) | a < 0 - = singleton '-' <> showbFixed chopTrailingZeroes (asTypeOf (MkFixed (negate a)) fa) -showbFixed chopTrailingZeroes fa@(MkFixed a) - = showb i <> withDotB (showbIntegerZeroes chopTrailingZeroes digits fracNum) - where - res = fromInteger $ resolution fa - (i, d) = divMod (fromInteger a) res - digits = ceiling (logBase 10 (fromInteger $ resolution fa) :: Double) - maxnum = 10 ^ digits -# if MIN_VERSION_base(4,8,0) - fracNum = divCeil (d * maxnum) res - divCeil x y = (x + y - 1) `div` y -# else - fracNum = div (d * maxnum) res -# endif -#else -showbFixed chopTrailingZeroes = fromString . showFixed chopTrailingZeroes -{-# INLINE showbFixed #-} -#endif - -#if MIN_VERSION_base(4,7,0) --- | Only works for positive 'Integer's. -showbIntegerZeroes :: Bool -> Int64 -> Integer -> Builder -showbIntegerZeroes True _ 0 = mempty -showbIntegerZeroes chopTrailingZeroes digits a - = timesN (fromIntegral . max 0 $ digits - lengthB sh) (singleton '0') <> sh' - where - sh, sh' :: Builder - sh = showb a - sh' = if chopTrailingZeroes then chopZeroesB a else sh - --- | Chops off the trailing zeroes of an 'Integer'. -chopZeroesB :: Integer -> Builder -chopZeroesB 0 = mempty -chopZeroesB a | mod a 10 == 0 = chopZeroesB (div a 10) -chopZeroesB a = showb a - --- | Prepends a dot to a non-empty 'Builder'. -withDotB :: Builder -> Builder -withDotB b | b == mempty = mempty - | otherwise = singleton '.' <> b -{-# INLINE withDotB #-} -#endif - -instance HasResolution a => Show (Fixed a) where - showb = showbFixed False - INLINE_INST_FUN(showb)
− src/Text/Show/Text/Data/Floating.hs
@@ -1,413 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Floating -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for floating-point types. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Floating ( - showbRealFloatPrec - , showbFloatPrec - , showbDoublePrec - , showbEFloat - , showbFFloat - , showbGFloat - , showbFFloatAlt - , showbGFloatAlt - , showbFPFormat - , FPFormat(..) - , formatRealFloatB - , formatRealFloatAltB - ) where - -import Data.Array.Base (unsafeAt) -import Data.Array.IArray (Array, array) -import Data.Monoid.Compat ((<>)) -import qualified Data.Text as T (replicate) -import Data.Text.Lazy.Builder (Builder, fromString, fromText, singleton) -import Data.Text.Lazy.Builder.Int (decimal) -import Data.Text.Lazy.Builder.RealFloat (FPFormat(..)) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), showbParen) -import Text.Show.Text.TH.Internal (deriveShow) -import Text.Show.Text.Utils (i2d) - -#include "inline.h" - --- | Convert a 'RealFloat' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbRealFloatPrec :: RealFloat a => Int -> a -> Builder -showbRealFloatPrec p x - | x < 0 || isNegativeZero x = showbParen (p > 6) $ singleton '-' <> showbGFloat Nothing (-x) - | otherwise = showbGFloat Nothing x -{-# INLINE showbRealFloatPrec #-} - --- | Convert a 'Float' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbFloatPrec :: Int -> Float -> Builder -showbFloatPrec = showbRealFloatPrec -{-# INLINE showbFloatPrec #-} - --- | Convert a 'Double' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbDoublePrec :: Int -> Double -> Builder -showbDoublePrec = showbRealFloatPrec -{-# INLINE showbDoublePrec #-} - --- | Show a signed 'RealFloat' value --- using scientific (exponential) notation (e.g. @2.45e2@, @1.5e-3@). --- --- In the call @'showbEFloat' digs val@, if @digs@ is 'Nothing', --- the value is shown to full precision; if @digs@ is @'Just' d@, --- then at most @d@ digits after the decimal point are shown. --- --- /Since: 0.3/ -showbEFloat :: RealFloat a => Maybe Int -> a -> Builder -showbEFloat = formatRealFloatB Exponent -{-# INLINE showbEFloat #-} - --- | Show a signed 'RealFloat' value --- using standard decimal notation (e.g. @245000@, @0.0015@). --- --- In the call @'showbFFloat' digs val@, if @digs@ is 'Nothing', --- the value is shown to full precision; if @digs@ is @'Just' d@, --- then at most @d@ digits after the decimal point are shown. --- --- /Since: 0.3/ -showbFFloat :: RealFloat a => Maybe Int -> a -> Builder -showbFFloat = formatRealFloatB Fixed -{-# INLINE showbFFloat #-} - --- | Show a signed 'RealFloat' value --- using standard decimal notation for arguments whose absolute value lies --- between @0.1@ and @9,999,999@, and scientific notation otherwise. --- --- In the call @'showbGFloat' digs val@, if @digs@ is 'Nothing', --- the value is shown to full precision; if @digs@ is @'Just' d@, --- then at most @d@ digits after the decimal point are shown. --- --- /Since: 0.3/ -showbGFloat :: RealFloat a => Maybe Int -> a -> Builder -showbGFloat = formatRealFloatB Generic -{-# INLINE showbGFloat #-} - --- | Show a signed 'RealFloat' value --- using standard decimal notation (e.g. @245000@, @0.0015@). --- --- This behaves as 'showFFloat', except that a decimal point --- is always guaranteed, even if not needed. --- --- /Since: 0.3/ -showbFFloatAlt :: RealFloat a => Maybe Int -> a -> Builder -showbFFloatAlt d = formatRealFloatAltB Fixed d True -{-# INLINE showbFFloatAlt #-} - --- | Show a signed 'RealFloat' value --- using standard decimal notation for arguments whose absolute value lies --- between @0.1@ and @9,999,999@, and scientific notation otherwise. --- --- This behaves as 'showFFloat', except that a decimal point --- is always guaranteed, even if not needed. --- --- /Since: 0.3/ -showbGFloatAlt :: RealFloat a => Maybe Int -> a -> Builder -showbGFloatAlt d = formatRealFloatAltB Generic d True -{-# INLINE showbGFloatAlt #-} - --- | Convert an 'FPFormat' value to a 'Builder'. --- --- /Since: 0.9/ -showbFPFormat :: FPFormat -> Builder -showbFPFormat = showb -{-# INLINE showbFPFormat #-} - -------------------------------------------------------------------------------- --- GHC.Float internal functions, adapted for Builders -------------------------------------------------------------------------------- - --- | Like 'formatRealFloatAltB', except that the decimal is only shown for arguments --- whose absolute value is between @0.1@ and @9,999,999@. --- --- /Since: 0.8/ -formatRealFloatB :: RealFloat a - => FPFormat -- ^ What notation to use. - -> Maybe Int -- ^ Number of decimal places to render. - -> a - -> Builder -formatRealFloatB fmt decs = formatRealFloatAltB fmt decs False -{-# INLINE formatRealFloatB #-} - --- | Converts a 'RealFloat' value to a Builder, specifying if a decimal point --- should always be shown. --- --- /Since: 0.8/ -formatRealFloatAltB :: RealFloat a - => FPFormat -- ^ What notation to use. - -> Maybe Int -- ^ Number of decimal places to render. - -> Bool -- ^ Should a decimal point always be shown? - -> a - -> Builder -{-# SPECIALIZE formatRealFloatAltB :: FPFormat -> Maybe Int -> Bool -> Float -> Builder #-} -{-# SPECIALIZE formatRealFloatAltB :: FPFormat -> Maybe Int -> Bool -> Double -> Builder #-} -formatRealFloatAltB fmt decs alt x - | isNaN x = "NaN" - | isInfinite x = if x < 0 then "-Infinity" else "Infinity" - | x < 0 || isNegativeZero x = singleton '-' <> doFmt fmt (floatToDigits (-x)) - | otherwise = doFmt fmt (floatToDigits x) - where - doFmt format (is, e) = - let ds = map i2d is in - case format of - Generic -> - doFmt (if e < 0 || e > 7 then Exponent else Fixed) - (is,e) - Exponent -> - case decs of - Nothing -> - let show_e' = decimal (e-1) in - case ds of - "0" -> "0.0e0" - [d] -> singleton d <> ".0e" <> show_e' - (d:ds') -> singleton d <> singleton '.' <> fromString ds' <> singleton 'e' <> show_e' - [] -> error "formatRealFloat/doFmt/Exponent: []" - Just dec -> - let dec' = max dec 1 in - case is of - [0] -> "0." <> fromText (T.replicate dec' "0") <> "e0" - _ -> - let - (ei,is') = roundTo (dec'+1) is - (d:ds') = map i2d (if ei > 0 then init is' else is') - in - singleton d <> singleton '.' <> fromString ds' <> singleton 'e' <> decimal (e-1+ei) - Fixed -> - let - mk0 ls = case ls of { "" -> "0" ; _ -> fromString ls} - in - case decs of - Nothing - | e <= 0 -> "0." <> fromText (T.replicate (-e) "0") <> fromString ds - | otherwise -> - let - f 0 str rs = mk0 (reverse str) <> singleton '.' <> mk0 rs - f n str "" = f (n-1) ('0':str) "" - f n str (r:rs) = f (n-1) (r:str) rs - in - f e "" ds - Just dec -> - let dec' = max dec 0 in - if e >= 0 then - let - (ei,is') = roundTo (dec' + e) is - (ls,rs) = splitAt (e+ei) (map i2d is') - in - mk0 ls <> (if null rs && not alt then "" else singleton '.' <> fromString rs) - else - let - (ei,is') = roundTo dec' (replicate (-e) 0 ++ is) - d:ds' = map i2d (if ei > 0 then is' else 0:is') - in - singleton d <> (if null ds' && not alt then "" else singleton '.' <> fromString ds') - --- Based on "Printing Floating-Point Numbers Quickly and Accurately" --- by R.G. Burger and R.K. Dybvig in PLDI 96. --- This version uses a much slower logarithm estimator. It should be improved. - --- | 'floatToDigits' takes a base and a non-negative 'RealFloat' number, --- and returns a list of digits and an exponent. --- In particular, if @x>=0@, and --- --- > floatToDigits base x = ([d1,d2,...,dn], e) --- --- then --- --- (1) @n >= 1@ --- --- (2) @x = 0.d1d2...dn * (base**e)@ --- --- (3) @0 <= di <= base-1@ -floatToDigits :: (RealFloat a) => a -> ([Int], Int) -{-# SPECIALIZE floatToDigits :: Float -> ([Int], Int) #-} -{-# SPECIALIZE floatToDigits :: Double -> ([Int], Int) #-} -floatToDigits 0 = ([0], 0) -floatToDigits x = - let - (f0, e0) = decodeFloat x - (minExp0, _) = floatRange x - p = floatDigits x - b = floatRadix x - minExp = minExp0 - p -- the real minimum exponent - -- Haskell requires that f be adjusted so denormalized numbers - -- will have an impossibly low exponent. Adjust for this. - (f, e) = - let n = minExp - e0 in - if n > 0 then (f0 `quot` (expt b n), e0+n) else (f0, e0) - (r, s', mUp, mDn) = - if e >= 0 then - let be = expt b e in - if f == expt b (p-1) then - (f*be*b*2, 2*b, be*b, be) -- according to Burger and Dybvig - else - (f*be*2, 2, be, be) - else - if e > minExp && f == expt b (p-1) then - (f*b*2, expt b (-e+1)*2, b, 1) - else - (f*2, expt b (-e)*2, 1, 1) - k :: Int - k = - let - k0 :: Int - k0 = - if b == 2 then - -- logBase 10 2 is very slightly larger than 8651/28738 - -- (about 5.3558e-10), so if log x >= 0, the approximation - -- k1 is too small, hence we add one and need one fixup step less. - -- If log x < 0, the approximation errs rather on the high side. - -- That is usually more than compensated for by ignoring the - -- fractional part of logBase 2 x, but when x is a power of 1/2 - -- or slightly larger and the exponent is a multiple of the - -- denominator of the rational approximation to logBase 10 2, - -- k1 is larger than logBase 10 x. If k1 > 1 + logBase 10 x, - -- we get a leading zero-digit we don't want. - -- With the approximation 3/10, this happened for - -- 0.5^1030, 0.5^1040, ..., 0.5^1070 and values close above. - -- The approximation 8651/28738 guarantees k1 < 1 + logBase 10 x - -- for IEEE-ish floating point types with exponent fields - -- <= 17 bits and mantissae of several thousand bits, earlier - -- convergents to logBase 10 2 would fail for long double. - -- Using quot instead of div is a little faster and requires - -- fewer fixup steps for negative lx. - let lx = p - 1 + e0 - k1 = (lx * 8651) `quot` 28738 - in if lx >= 0 then k1 + 1 else k1 - else - -- f :: Integer, log :: Float -> Float, - -- ceiling :: Float -> Int - ceiling ((log (fromInteger (f+1) :: Float) + - fromIntegral e * log (fromInteger b)) / - log 10) ---WAS: fromInt e * log (fromInteger b)) - - fixup n = - if n >= 0 then - if r + mUp <= expt 10 n * s' then n else fixup (n+1) - else - if expt 10 (-n) * (r + mUp) <= s' then n else fixup (n+1) - in - fixup k0 - - gen ds rn sN mUpN mDnN = - let - (dn, rn') = (rn * 10) `quotRem` sN - mUpN' = mUpN * 10 - mDnN' = mDnN * 10 - in - case (rn' < mDnN', rn' + mUpN' > sN) of - (True, False) -> dn : ds - (False, True) -> dn+1 : ds - (True, True) -> if rn' * 2 < sN then dn : ds else dn+1 : ds - (False, False) -> gen (dn:ds) rn' sN mUpN' mDnN' - - rds = - if k >= 0 then - gen [] r (s' * expt 10 k) mUp mDn - else - let bk = expt 10 (-k) in - gen [] (r * bk) s' (mUp * bk) (mDn * bk) - in - (map fromIntegral (reverse rds), k) - -roundTo :: Int -> [Int] -> (Int,[Int]) -#if MIN_VERSION_base(4,6,0) -roundTo d is = - case f d True is of - x@(0,_) -> x - (1,xs) -> (1, 1:xs) - _ -> error "roundTo: bad Value" - where - b2 = base `quot` 2 - - f n _ [] = (0, replicate n 0) - f 0 e (x:xs) | x == b2 && e && all (== 0) xs = (0, []) -- Round to even when at exactly half the base - | otherwise = (if x >= b2 then 1 else 0, []) - f n _ (i:xs) - | i' == base = (1,0:ds) - | otherwise = (0,i':ds) - where - (c,ds) = f (n-1) (even i) xs - i' = c + i - base = 10 -#else -roundTo d is = - case f d is of - x@(0,_) -> x - (1,xs) -> (1, 1:xs) - _ -> error "roundTo: bad Value" - where - f n [] = (0, replicate n 0) - f 0 (x:_) = (if x >= 5 then 1 else 0, []) - f n (i:xs) - | i' == 10 = (1,0:ds) - | otherwise = (0,i':ds) - where - (c,ds) = f (n-1) xs - i' = c + i -#endif - --- Exponentiation with a cache for the most common numbers. - --- | The minimum exponent in the cache. -minExpt :: Int -minExpt = 0 - --- | The maximum exponent (of 2) in the cache. -maxExpt :: Int -maxExpt = 1100 - --- | Exponentiate an 'Integer', using a cache if possible. -expt :: Integer -> Int -> Integer -expt base n - | base == 2 && n >= minExpt && n <= maxExpt = expts `unsafeAt` n - | base == 10 && n <= maxExpt10 = expts10 `unsafeAt` n - | otherwise = base^n - --- | Cached powers of two. -expts :: Array Int Integer -expts = array (minExpt,maxExpt) [(n,2^n) | n <- [minExpt .. maxExpt]] - --- | The maximum exponent (of 10) in the cache. -maxExpt10 :: Int -maxExpt10 = 324 - --- | Cached powers of 10. -expts10 :: Array Int Integer -expts10 = array (minExpt,maxExpt10) [(n,10^n) | n <- [minExpt .. maxExpt10]] - -------------------------------------------------------------------------------- --- Show instances -------------------------------------------------------------------------------- - -instance Show Float where - showbPrec = showbFloatPrec - INLINE_INST_FUN(showbPrec) - -instance Show Double where - showbPrec = showbDoublePrec - INLINE_INST_FUN(showbPrec) - -$(deriveShow ''FPFormat)
− src/Text/Show/Text/Data/Functor/Identity.hs
@@ -1,43 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Functor.Identity -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Identity' values. - -/Since: 0.5/ --} -module Text.Show.Text.Data.Functor.Identity (showbIdentityPrecWith) where - -import Data.Functor.Identity (Identity(..)) -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec), Show1(..), showbPrec1, showbUnaryWith) - -#include "inline.h" - --- | Convert an 'Identity' value to a 'Builder' with the given show function --- and precedence. --- --- /Since: 1/ -showbIdentityPrecWith :: (Int -> a -> Builder) -> Int -> Identity a -> Builder --- This would be equivalent to the derived instance of 'Identity' if the --- 'runIdentity' field were removed. -showbIdentityPrecWith sp p (Identity x) = showbUnaryWith sp "Identity" p x -{-# INLINE showbIdentityPrecWith #-} - -instance Show a => Show (Identity a) where - showbPrec = showbPrec1 - {-# INLINE showbPrec #-} - -instance Show1 Identity where - showbPrecWith = showbIdentityPrecWith - INLINE_INST_FUN(showbPrecWith)
− src/Text/Show/Text/Data/Integral.hs
@@ -1,241 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE MagicHash #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Integral -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for integral types. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Integral ( - showbIntPrec - , showbInt8Prec - , showbInt16Prec - , showbInt32Prec - , showbInt64Prec - , showbIntegerPrec - , showbIntegralPrec - , showbIntAtBase - , showbBin - , showbHex - , showbOct - , showbWord - , showbWord8 - , showbWord16 - , showbWord32 - , showbWord64 - ) where - -import Data.Char (intToDigit) -import Data.Int (Int8, Int16, Int32, Int64) -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, singleton) -import Data.Text.Lazy.Builder.Int (decimal) -import Data.Word (Word8, Word16, Word32, Word64) - -import GHC.Exts (Int(I#)) -#if __GLASGOW_HASKELL__ >= 708 -import GHC.Exts (isTrue#) -import GHC.Prim (Int#) -#endif -import GHC.Prim ((<#), (>#)) - -import Prelude () -import Prelude.Compat hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec)) -import Text.Show.Text.Utils (toString) - -#include "inline.h" - --- | Convert an 'Int' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbIntPrec :: Int -> Int -> Builder -showbIntPrec (I# p) n'@(I# n) - | isTrue (n <# 0#) && isTrue (p ># 6#) = singleton '(' <> decimal n' <> singleton ')' - | otherwise = decimal n' - where -#if __GLASGOW_HASKELL__ >= 708 - isTrue :: Int# -> Bool - isTrue b = isTrue# b -#else - isTrue :: Bool -> Bool - isTrue = id -#endif - --- | Convert an 'Int8' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbInt8Prec :: Int -> Int8 -> Builder -showbInt8Prec p = showbIntPrec p . fromIntegral -{-# INLINE showbInt8Prec #-} - --- | Convert an 'Int16' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbInt16Prec :: Int -> Int16 -> Builder -showbInt16Prec p = showbIntPrec p . fromIntegral -{-# INLINE showbInt16Prec #-} - --- | Convert an 'Int32' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbInt32Prec :: Int -> Int32 -> Builder -showbInt32Prec p = showbIntPrec p . fromIntegral -{-# INLINE showbInt32Prec #-} - --- | Convert an 'Int64' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbInt64Prec :: Int -> Int64 -> Builder -#if WORD_SIZE_IN_BITS < 64 -showbInt64Prec p = showbIntegerPrec p . toInteger -#else -showbInt64Prec p = showbIntPrec p . fromIntegral -#endif -{-# INLINE showbInt64Prec #-} - --- | Convert an 'Integer' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbIntegerPrec :: Int -> Integer -> Builder -showbIntegerPrec p n - | p > 6 && n < 0 = singleton '(' <> decimal n <> singleton ')' - | otherwise = decimal n -{-# INLINE showbIntegerPrec #-} - --- | Convert an 'Integral' type to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbIntegralPrec :: Integral a => Int -> a -> Builder -showbIntegralPrec p = showbIntegerPrec p . toInteger -{-# INLINE showbIntegralPrec #-} - --- | Shows a /non-negative/ 'Integral' number using the base specified by the --- first argument, and the character representation specified by the second. --- --- /Since: 0.3/ -showbIntAtBase :: (Integral a, Show a) => a -> (Int -> Char) -> a -> Builder -showbIntAtBase base toChr n0 - | base <= 1 = error . toString $ "Text.Show.Text.Int.showbIntAtBase: applied to unsupported base" <> showb base - | n0 < 0 = error . toString $ "Text.Show.Text.Int.showbIntAtBase: applied to negative number " <> showb n0 - | otherwise = showbIt (quotRem n0 base) mempty - where - showbIt (n, d) b = seq c $ -- stricter than necessary - case n of - 0 -> b' - _ -> showbIt (quotRem n base) b' - where - c :: Char - c = toChr $ fromIntegral d - - b' :: Builder - b' = singleton c <> b - --- | Show /non-negative/ 'Integral' numbers in base 2. --- --- /Since: 0.3/ -showbBin :: (Integral a, Show a) => a -> Builder -showbBin = showbIntAtBase 2 intToDigit -{-# INLINE showbBin #-} - --- | Show /non-negative/ 'Integral' numbers in base 16. --- --- /Since: 0.3/ -showbHex :: (Integral a, Show a) => a -> Builder -showbHex = showbIntAtBase 16 intToDigit -{-# INLINE showbHex #-} - --- | Show /non-negative/ 'Integral' numbers in base 8. --- --- /Since: 0.3/ -showbOct :: (Integral a, Show a) => a -> Builder -showbOct = showbIntAtBase 8 intToDigit -{-# INLINE showbOct #-} - --- | Convert a 'Word' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbWord :: Word -> Builder -showbWord = decimal -{-# INLINE showbWord #-} - --- | Convert a 'Word8' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbWord8 :: Word8 -> Builder -showbWord8 = decimal -{-# INLINE showbWord8 #-} - --- | Convert a 'Word16' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbWord16 :: Word16 -> Builder -showbWord16 = decimal -{-# INLINE showbWord16 #-} - --- | Convert a 'Word32' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbWord32 :: Word32 -> Builder -showbWord32 = decimal -{-# INLINE showbWord32 #-} - --- | Convert a 'Word64' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbWord64 :: Word64 -> Builder -showbWord64 = decimal -{-# INLINE showbWord64 #-} - -instance Show Int where - showbPrec = showbIntPrec - INLINE_INST_FUN(showbPrec) - -instance Show Int8 where - showbPrec = showbInt8Prec - INLINE_INST_FUN(showbPrec) - -instance Show Int16 where - showbPrec = showbInt16Prec - INLINE_INST_FUN(showbPrec) - -instance Show Int32 where - showbPrec = showbInt32Prec - INLINE_INST_FUN(showbPrec) - -instance Show Int64 where - showbPrec = showbInt64Prec - INLINE_INST_FUN(showbPrec) - -instance Show Integer where - showbPrec = showbIntegerPrec - INLINE_INST_FUN(showbPrec) - -instance Show Word where - showb = showbWord - INLINE_INST_FUN(showb) - -instance Show Word8 where - showb = showbWord8 - INLINE_INST_FUN(showb) - -instance Show Word16 where - showb = showbWord16 - INLINE_INST_FUN(showb) - -instance Show Word32 where - showb = showbWord32 - INLINE_INST_FUN(showb) - -instance Show Word64 where - showb = showbWord64 - INLINE_INST_FUN(showb)
− src/Text/Show/Text/Data/List.hs
@@ -1,32 +0,0 @@-{-# LANGUAGE CPP #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.List -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Exports 'showbListWith'. --} -module Text.Show.Text.Data.List (showbListWith) where - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbList), Show1(..), showbListWith) -import Text.Show.Text.Data.Char () -import Text.Show.Text.Data.Integral () - -#include "inline.h" - -instance Show a => Show [a] where - {-# SPECIALIZE instance Show [String] #-} - {-# SPECIALIZE instance Show String #-} - {-# SPECIALIZE instance Show [Int] #-} - showb = showbList - INLINE_INST_FUN(showb) - -instance Show1 [] where - showbPrecWith sp _ = showbListWith (sp 0) - INLINE_INST_FUN(showbPrecWith)
− src/Text/Show/Text/Data/Maybe.hs
@@ -1,35 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Maybe -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Maybe' values. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Maybe (showbMaybePrecWith) where - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (showbPrecWith) -import Text.Show.Text.TH.Internal (deriveShow, deriveShow1) - -#include "inline.h" - --- | Convert a 'Maybe' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbMaybePrecWith :: (Int -> a -> Builder) -> Int -> Maybe a -> Builder -showbMaybePrecWith = showbPrecWith -{-# INLINE showbMaybePrecWith #-} - -$(deriveShow ''Maybe) -$(deriveShow1 ''Maybe)
− src/Text/Show/Text/Data/Monoid.hs
@@ -1,136 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -#if MIN_VERSION_base(4,8,0) -{-# LANGUAGE FlexibleContexts #-} -#endif -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Monoid -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for 'Monoid'-related newtypes. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Monoid ( - showbAllPrec - , showbAnyPrec - , showbDualPrecWith - , showbFirstPrecWith - , showbLastPrecWith - , showbProductPrecWith - , showbSumPrecWith -#if MIN_VERSION_base(4,8,0) - , showbAltPrec - , showbAltPrecWith -#endif - ) where - -import Data.Monoid.Compat (All, Any, Dual, First, Last, Product, Sum) -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec), showbPrecWith) -import Text.Show.Text.Data.Bool () -import Text.Show.Text.Data.Maybe () -import Text.Show.Text.TH.Internal (deriveShow, deriveShow1) - -#if MIN_VERSION_base(4,8,0) -import Data.Monoid (Alt) -import Text.Show.Text.Classes (Show1) -import Text.Show.Text.TH.Internal (mkShowbPrec) -#endif - -#include "inline.h" - --- | Convert an 'All' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbAllPrec :: Int -> All -> Builder -showbAllPrec = showbPrec -{-# INLINE showbAllPrec #-} - --- | Convert an 'Any' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbAnyPrec :: Int -> Any -> Builder -showbAnyPrec = showbPrec -{-# INLINE showbAnyPrec #-} - --- | Convert a 'Dual' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbDualPrecWith :: (Int -> a -> Builder) -> Int -> Dual a -> Builder -showbDualPrecWith = showbPrecWith -{-# INLINE showbDualPrecWith #-} - --- | Convert a 'First' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbFirstPrecWith :: (Int -> a -> Builder) -> Int -> First a -> Builder -showbFirstPrecWith = showbPrecWith -{-# INLINE showbFirstPrecWith #-} - --- | Convert a 'Last' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbLastPrecWith :: (Int -> a -> Builder) -> Int -> Last a -> Builder -showbLastPrecWith = showbPrecWith -{-# INLINE showbLastPrecWith #-} - --- | Convert a 'Product' value to a 'Builder' with the given show function --- and precedence. --- --- /Since: 1/ -showbProductPrecWith :: (Int -> a -> Builder) -> Int -> Product a -> Builder -showbProductPrecWith = showbPrecWith -{-# INLINE showbProductPrecWith #-} - --- | Convert a 'Sum' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbSumPrecWith :: (Int -> a -> Builder) -> Int -> Sum a -> Builder -showbSumPrecWith = showbPrecWith -{-# INLINE showbSumPrecWith #-} - -#if MIN_VERSION_base(4,8,0) --- | Convert an 'Alt' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.8/ -showbAltPrec :: Show (f a) => Int -> Alt f a -> Builder -showbAltPrec = showbPrec -{-# INLINE showbAltPrec #-} - --- | Convert an 'Alt' value to a 'Builder' with the given show function and precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 1/ -showbAltPrecWith :: Show1 f => (Int -> a -> Builder) -> Int -> Alt f a -> Builder -showbAltPrecWith = showbPrecWith -#endif - -$(deriveShow ''All) -$(deriveShow ''Any) -$(deriveShow ''Dual) -$(deriveShow1 ''Dual) -$(deriveShow ''First) -$(deriveShow1 ''First) -$(deriveShow ''Last) -$(deriveShow1 ''Last) -$(deriveShow ''Product) -$(deriveShow1 ''Product) -$(deriveShow ''Sum) -$(deriveShow1 ''Sum) - -#if MIN_VERSION_base(4,8,0) -instance Show (f a) => Show (Alt f a) where - showbPrec = $(mkShowbPrec ''Alt) - -$(deriveShow1 ''Alt) -#endif
− src/Text/Show/Text/Data/OldTypeable.hs
@@ -1,78 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,7,0) && !(MIN_VERSION_base(4,8,0)) -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-warnings-deprecations #-} -#endif -{-| -Module: Text.Show.Text.Data.OldTypeable -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the @OldTypeable@ module. -This module only exports functions if using @base-4.7@. - -/Since: 0.5/ --} -module Text.Show.Text.Data.OldTypeable ( -#if !(MIN_VERSION_base(4,7,0)) || MIN_VERSION_base(4,8,0) - ) where -#else - showbTyCon - , showbTypeRepPrec - ) where - -import Data.Monoid.Compat ((<>)) -import Data.OldTypeable.Internal (TyCon(TyCon, tyConName), TypeRep(..), - funTc, listTc) -import Data.Text.Lazy.Builder (Builder, fromString, singleton) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), showbParen, showbSpace) -import Text.Show.Text.Data.Typeable.Utils (showbArgs, showbTuple) -import Text.Show.Text.Utils (isTupleString) - --- | Convert a 'TyCon' to a 'Builder'. --- This function is only available with @base-4.7@. --- --- /Since: 0.5/ -showbTyCon :: TyCon -> Builder -showbTyCon = fromString . tyConName -{-# INLINE showbTyCon #-} - --- | Convert a 'TypeRep' to a 'Builder' with the given precedence. --- This function is only available with @base-4.7@. --- --- /Since: 0.5/ -showbTypeRepPrec :: Int -> TypeRep -> Builder -showbTypeRepPrec p (TypeRep _ tycon tys) = - case tys of - [] -> showbTyCon tycon - [x] | tycon == listTc -> singleton '[' <> showb x <> singleton ']' - [a,r] | tycon == funTc -> showbParen (p > 8) $ - showbPrec 9 a - <> " -> " - <> showbPrec 8 r - xs | isTupleTyCon tycon -> showbTuple xs - | otherwise -> showbParen (p > 9) $ - showbPrec p tycon - <> showbSpace - <> showbArgs showbSpace tys - --- | Does the 'TyCon' represent a tuple type constructor? -isTupleTyCon :: TyCon -> Bool -isTupleTyCon (TyCon _ _ _ str) = isTupleString str -{-# INLINE isTupleTyCon #-} - -instance Show TyCon where - showb = showbTyCon - {-# INLINE showb #-} - -instance Show TypeRep where - showbPrec = showbTypeRepPrec - {-# INLINE showbPrec #-} -#endif
− src/Text/Show/Text/Data/Ord.hs
@@ -1,63 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Ord -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for 'Ordering' and 'Down'. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Ord ( - showbOrdering -#if MIN_VERSION_base(4,6,0) - , showbDownPrecWith -#endif - ) where - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (showb) -import Text.Show.Text.TH.Internal (deriveShow) - -#if MIN_VERSION_base(4,6,0) -import Data.Ord (Down) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (showbPrecWith) -import Text.Show.Text.TH.Internal (deriveShow1) -#endif - -#include "inline.h" - --- | Convert a 'Ordering' to a 'Builder'. --- --- /Since: 0.3/ -showbOrdering :: Ordering -> Builder -showbOrdering = showb -{-# INLINE showbOrdering #-} - -#if MIN_VERSION_base(4,6,0) --- | Convert a 'Down' value to a 'Builder' with the given show function and precedence. --- This function is only available with @base-4.6.0.0@ or later. --- --- /Since: 1/ -showbDownPrecWith :: (Int -> a -> Builder) -> Int -> Down a -> Builder -showbDownPrecWith = showbPrecWith -{-# INLINE showbDownPrecWith #-} -#endif - -$(deriveShow ''Ordering) - -#if MIN_VERSION_base(4,6,0) -$(deriveShow ''Down) -$(deriveShow1 ''Down) -#endif
− src/Text/Show/Text/Data/Proxy.hs
@@ -1,40 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Proxy -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Proxy' values. - -/Since: 0.4/ --} -module Text.Show.Text.Data.Proxy (showbProxy) where - -import Data.Proxy (Proxy(..)) -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), showbPrecWith) -import Text.Show.Text.TH.Internal (deriveShow1) - -#include "inline.h" - --- | Convert a 'Proxy' type to a 'Builder'. --- --- /Since: 0.4/ -showbProxy :: Proxy s -> Builder -showbProxy = showb -{-# INLINE showbProxy #-} - -instance Show (Proxy s) where - showbPrec = showbPrecWith undefined - INLINE_INST_FUN(showb) - -$(deriveShow1 ''Proxy)
− src/Text/Show/Text/Data/Ratio.hs
@@ -1,70 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Ratio -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Ratio' values. - -/Since: 0.5/ --} -module Text.Show.Text.Data.Ratio (showbRatioPrec) where - -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder) - -import GHC.Real (Ratio(..), ratioPrec, ratioPrec1) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec), showbParen) -#if MIN_VERSION_base(4,4,0) -import Text.Show.Text.Classes (Show1(..)) -#endif -import Text.Show.Text.Data.Integral () - -#include "inline.h" - --- | Convert a 'Ratio' to a 'Builder' with the given precedence. --- --- Note that on @base-4.3.0.0@, this function must have a @('Show' a, 'Integral' a)@ --- constraint instead of just a @('Show' a)@ constraint. --- --- /Since: 0.5/ -showbRatioPrec :: -#if MIN_VERSION_base(4,4,0) - Show a -#else - (Show a, Integral a) -#endif - => Int -> Ratio a -> Builder -showbRatioPrec p (numer :% denom) = showbParen (p > ratioPrec) $ - showbPrec ratioPrec1 numer - <> " % " - <> showbPrec ratioPrec1 denom -{-# INLINE showbRatioPrec #-} - -instance -#if MIN_VERSION_base(4,4,0) - Show a -#else - (Show a, Integral a) -#endif - => Show (Ratio a) where - {-# SPECIALIZE instance Show Rational #-} - showbPrec = showbRatioPrec - INLINE_INST_FUN(showbPrec) - -#if MIN_VERSION_base(4,4,0) -instance Show1 Ratio where - showbPrecWith sp p (numer :% denom) = showbParen (p > ratioPrec) $ - sp ratioPrec1 numer - <> " % " - <> sp ratioPrec1 denom - INLINE_INST_FUN(showbPrecWith) -#endif
− src/Text/Show/Text/Data/Text.hs
@@ -1,156 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -#if MIN_VERSION_text(0,9,0) -{-# LANGUAGE TemplateHaskell #-} -#endif -{-# OPTIONS_GHC -fno-warn-deprecations #-} -- TODO: Remove this later -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Text -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for 'Text' types. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Text ( - showbText - , showbTextLazy - , showbBuilder - , showbI16Prec - , showbUnicodeException -#if MIN_VERSION_text(1,0,0) - , showbDecodingPrec -#endif -#if MIN_VERSION_text(1,1,0) - , showbSizePrec -#endif - ) where - -import Data.Monoid.Compat ((<>)) -import qualified Data.Text as TS -import Data.Text.Encoding.Error (UnicodeException(..)) -import Data.Text.Foreign (I16) -import qualified Data.Text.Lazy as TL -import Data.Text.Lazy.Builder (Builder, fromString, toLazyText) -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec)) -import Text.Show.Text.Data.Char (showbString) -import Text.Show.Text.Data.Integral (showbHex) -import Text.Show.Text.TH.Internal (deriveShow) - -#if MIN_VERSION_text(1,0,0) -import Data.Text.Encoding (Decoding(..)) -import Data.Text.Lazy.Builder (singleton) -import GHC.Show (appPrec) -import Text.Show.Text.Classes (showbParen) -import Text.Show.Text.Data.ByteString (showbByteStringStrict) -#endif - -#if MIN_VERSION_text(1,1,0) -import Data.Text.Internal.Fusion.Size (Size) -#endif - -#include "inline.h" - --- | Convert a strict 'TS.Text' to a 'Builder'. --- 'showbText' should not be confused with @fromText@, as 'showbText' escapes --- certain characters (such as double quotes). --- --- /Since: 0.5/ -showbText :: TS.Text -> Builder -showbText = showbString . TS.unpack -{-# INLINE showbText #-} - --- | Convert a lazy 'TL.Text' to a 'Builder'. --- 'showbTextLazy' should not be confused with @fromTextLazy@, as 'showbTextLazy' --- escapes certain characters (such as double quotes). --- --- /Since: 0.3/ -showbTextLazy :: TL.Text -> Builder -showbTextLazy = showbString . TL.unpack -{-# INLINE showbTextLazy #-} - --- | Show a 'Builder' as if it were a 'String' (i.e., escape certain characters, --- such as double quotes). --- --- /Since: 0.5/ -showbBuilder :: Builder -> Builder -showbBuilder = showbTextLazy . toLazyText -{-# INLINE showbBuilder #-} - --- | Convert an 'I16' value to a 'Builder' with the given precedence. --- --- /Since: 0.8/ -showbI16Prec :: Int -> I16 -> Builder -showbI16Prec = showbPrec -{-# INLINE showbI16Prec #-} - --- | Convert a 'UnicodeException' to a 'Builder'. --- --- /Since: 0.8/ -showbUnicodeException :: UnicodeException -> Builder -showbUnicodeException (DecodeError desc (Just w)) - = "Cannot decode byte '\\x" <> showbHex w <> "': " <> fromString desc -showbUnicodeException (DecodeError desc Nothing) - = "Cannot decode input: " <> fromString desc -showbUnicodeException (EncodeError desc (Just c)) - = "Cannot encode character '\\x" <> showbHex (fromEnum c) <> "': " <> fromString desc -showbUnicodeException (EncodeError desc Nothing) - = "Cannot encode input: " <> fromString desc - -#if MIN_VERSION_text(1,0,0) --- | Convert a 'Decoding' value to a 'Builder' with the given precedence. --- This function is only available with @text-1.0.0.0@ or later. --- --- /Since: 0.8/ -showbDecodingPrec :: Int -> Decoding -> Builder -showbDecodingPrec p (Some t bs _) = showbParen (p > appPrec) $ - fromString "Some " <> showbText t <> - singleton ' ' <> showbByteStringStrict bs <> - fromString " _" -{-# INLINE showbDecodingPrec #-} -#endif - -#if MIN_VERSION_text(1,1,0) --- | Convert a 'Size' value to a 'Builder' with the given precedence. --- This function is only available with @text-1.1.0.0@ or later. --- --- /Since: 0.8/ -showbSizePrec :: Int -> Size -> Builder -showbSizePrec = showbPrec -{-# INLINE showbSizePrec #-} -#endif - -instance Show TS.Text where - showb = showbText - INLINE_INST_FUN(showb) - -instance Show TL.Text where - showb = showbTextLazy - INLINE_INST_FUN(showb) - -instance Show Builder where - showb = showbBuilder - INLINE_INST_FUN(showb) - -$(deriveShow ''I16) - -instance Show UnicodeException where - showb = showbUnicodeException - INLINE_INST_FUN(showb) - -#if MIN_VERSION_text(1,0,0) -instance Show Decoding where - showbPrec = showbDecodingPrec - INLINE_INST_FUN(showbPrec) -#endif - -#if MIN_VERSION_text(1,1,0) -$(deriveShow ''Size) -#endif
− src/Text/Show/Text/Data/Tuple.hs
@@ -1,231 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Tuple -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for tuple types. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Tuple ( - showbUnit - , showb2TupleWith2 - , showb3TupleWith2 - , showb4TupleWith2 - , showb5TupleWith2 - , showb6TupleWith2 - , showb7TupleWith2 - , showb8TupleWith2 - , showb9TupleWith2 - , showb10TupleWith2 - , showb11TupleWith2 - , showb12TupleWith2 - , showb13TupleWith2 - , showb14TupleWith2 - , showb15TupleWith2 - ) where - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb), Show2(..)) -import Text.Show.Text.TH.Internal (deriveShow, deriveShow1, deriveShow2) - -#include "inline.h" - --- | Converts @()@ into a 'Builder'. --- --- /Since: 0.3/ -showbUnit :: () -> Builder --- showbUnit () = "()" -showbUnit = showb -{-# INLINE showbUnit #-} - --- | Converts a 2-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb2TupleWith2 :: (a -> Builder) -> (b -> Builder) - -> (a, b) -> Builder -showb2TupleWith2 = showbWith2 -{-# INLINE showb2TupleWith2 #-} - --- | Converts a 3-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb3TupleWith2 :: Show a - => (b -> Builder) -> (c -> Builder) - -> (a, b, c) -> Builder -showb3TupleWith2 = showbWith2 -{-# INLINE showb3TupleWith2 #-} - --- | Converts a 4-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb4TupleWith2 :: (Show a, Show b) - => (c -> Builder) -> (d -> Builder) - -> (a, b, c, d) -> Builder -showb4TupleWith2 = showbWith2 -{-# INLINE showb4TupleWith2 #-} - --- | Converts a 5-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb5TupleWith2 :: (Show a, Show b, Show c) - => (d -> Builder) -> (e -> Builder) - -> (a, b, c, d, e) -> Builder -showb5TupleWith2 = showbWith2 -{-# INLINE showb5TupleWith2 #-} - --- | Converts a 6-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb6TupleWith2 :: (Show a, Show b, Show c, Show d) - => (e -> Builder) -> (f -> Builder) - -> (a, b, c, d, e, f) -> Builder -showb6TupleWith2 = showbWith2 -{-# INLINE showb6TupleWith2 #-} - --- | Converts a 7-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb7TupleWith2 :: (Show a, Show b, Show c, Show d, Show e) - => (f -> Builder) -> (g -> Builder) - -> (a, b, c, d, e, f, g) -> Builder -showb7TupleWith2 = showbWith2 -{-# INLINE showb7TupleWith2 #-} - --- | Converts an 8-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb8TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f) - => (g -> Builder) -> (h -> Builder) - -> (a, b, c, d, e, f, g, h) -> Builder -showb8TupleWith2 = showbWith2 -{-# INLINE showb8TupleWith2 #-} - --- | Converts a 9-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb9TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g) - => (h -> Builder) -> (i -> Builder) - -> (a, b, c, d, e, f, g, h, i) -> Builder -showb9TupleWith2 = showbWith2 -{-# INLINE showb9TupleWith2 #-} - --- | Converts a 10-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb10TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) - => (i -> Builder) -> (j -> Builder) - -> (a, b, c, d, e, f, g, h, i, j) -> Builder -showb10TupleWith2 = showbWith2 -{-# INLINE showb10TupleWith2 #-} - --- | Converts an 11-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb11TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, - Show f, Show g, Show h, Show i) - => (j -> Builder) -> (k -> Builder) - -> (a, b, c, d, e, f, g, h, i, j, k) -> Builder -showb11TupleWith2 = showbWith2 -{-# INLINE showb11TupleWith2 #-} - --- | Converts a 12-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb12TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, - Show f, Show g, Show h, Show i, Show j) - => (k -> Builder) -> (l -> Builder) - -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Builder -showb12TupleWith2 = showbWith2 -{-# INLINE showb12TupleWith2 #-} - --- | Converts a 13-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb13TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, - Show g, Show h, Show i, Show j, Show k) - => (l -> Builder) -> (m -> Builder) - -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Builder -showb13TupleWith2 = showbWith2 -{-# INLINE showb13TupleWith2 #-} - --- | Converts a 14-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb14TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, - Show g, Show h, Show i, Show j, Show k, Show l) - => (m -> Builder) -> (n -> Builder) - -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Builder -showb14TupleWith2 = showbWith2 -{-# INLINE showb14TupleWith2 #-} - --- | Converts a 15-tuple into a 'Builder' with the given show functions. --- --- /Since: 1/ -showb15TupleWith2 :: (Show a, Show b, Show c, Show d, Show e, Show f, Show g, - Show h, Show i, Show j, Show k, Show l, Show m) - => (n -> Builder) -> (o -> Builder) - -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Builder -showb15TupleWith2 = showbWith2 -{-# INLINE showb15TupleWith2 #-} - --- | Like 'showbPrecWith2', except precedence-agnostic. -showbWith2 :: Show2 f => (a -> Builder) -> (b -> Builder) -> f a b -> Builder -showbWith2 sp1 sp2 = showbPrecWith2 (const sp1) (const sp2) 0 -{-# INLINE showbWith2 #-} - --- The Great Pyramids of Template Haskell -$(deriveShow ''()) -$(deriveShow ''(,)) -$(deriveShow ''(,,)) -$(deriveShow ''(,,,)) -$(deriveShow ''(,,,,)) -$(deriveShow ''(,,,,,)) -$(deriveShow ''(,,,,,,)) -$(deriveShow ''(,,,,,,,)) -$(deriveShow ''(,,,,,,,,)) -$(deriveShow ''(,,,,,,,,,)) -$(deriveShow ''(,,,,,,,,,,)) -$(deriveShow ''(,,,,,,,,,,,)) -$(deriveShow ''(,,,,,,,,,,,,)) -$(deriveShow ''(,,,,,,,,,,,,,)) -$(deriveShow ''(,,,,,,,,,,,,,,)) - -$(deriveShow1 ''(,)) -$(deriveShow1 ''(,,)) -$(deriveShow1 ''(,,,)) -$(deriveShow1 ''(,,,,)) -$(deriveShow1 ''(,,,,,)) -$(deriveShow1 ''(,,,,,,)) -$(deriveShow1 ''(,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,,,,,,)) -$(deriveShow1 ''(,,,,,,,,,,,,,,)) - -$(deriveShow2 ''(,)) -$(deriveShow2 ''(,,)) -$(deriveShow2 ''(,,,)) -$(deriveShow2 ''(,,,,)) -$(deriveShow2 ''(,,,,,)) -$(deriveShow2 ''(,,,,,,)) -$(deriveShow2 ''(,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,,,,,,)) -$(deriveShow2 ''(,,,,,,,,,,,,,,))
− src/Text/Show/Text/Data/Type/Coercion.hs
@@ -1,53 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,7,0) -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.Data.Type.Coercion -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for representational equality. -This module only exports functions if using @base-4.7.0.0@ or later. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Type.Coercion ( -#if !(MIN_VERSION_base(4,7,0)) - ) where -#else - showbCoercion - ) where - -import Data.Text.Lazy.Builder (Builder) -import Data.Type.Coercion (Coercion(..)) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), Show1(..), Show2(..)) -import Text.Show.Text.TH.Internal (deriveShow2) - --- | Convert a representational equality value to a 'Builder'. --- This function is only available with @base-4.7.0.0@ or later. --- --- /Since: 0.3/ -showbCoercion :: Coercion a b -> Builder -showbCoercion = showb -{-# INLINE showbCoercion #-} - -instance Show (Coercion a b) where - showbPrec = showbPrecWith undefined - {-# INLINE showb #-} - -instance Show1 (Coercion a) where - showbPrecWith = showbPrecWith2 undefined - {-# INLINE showbPrecWith #-} - -$(deriveShow2 ''Coercion) -#endif
− src/Text/Show/Text/Data/Type/Equality.hs
@@ -1,54 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,7,0) -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeOperators #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.Data.Type.Equality -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for propositional equality. -This module only exports functions if using @base-4.7.0.0@ or later. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Type.Equality ( -#if !(MIN_VERSION_base(4,7,0)) - ) where -#else - showbPropEquality - ) where - -import Data.Text.Lazy.Builder (Builder) -import Data.Type.Equality ((:~:)(..)) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), Show1(..), Show2(..)) -import Text.Show.Text.TH.Internal (deriveShow2) - --- | Convert a propositional equality value to a 'Builder'. --- This function is only available with @base-4.7.0.0@ or later. --- --- /Since: 0.3/ -showbPropEquality :: (a :~: b) -> Builder -showbPropEquality = showb -{-# INLINE showbPropEquality #-} - -instance Show (a :~: b) where - showbPrec = showbPrecWith undefined - {-# INLINE showbPrec #-} - -instance Show1 ((:~:) a) where - showbPrecWith = showbPrecWith2 undefined - {-# INLINE showbPrecWith #-} - -$(deriveShow2 ''(:~:)) -#endif
− src/Text/Show/Text/Data/Typeable.hs
@@ -1,104 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Typeable -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the @Typeable@ module. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Typeable (showbTyCon, showbTypeRepPrec) where - -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, fromString, singleton) -import Data.Typeable (TypeRep, typeRepArgs, typeRepTyCon) -#if MIN_VERSION_base(4,4,0) -import Data.Typeable.Internal (TyCon(..), funTc, listTc) -# if MIN_VERSION_base(4,8,0) -import Data.Typeable.Internal (typeRepKinds) -# endif -#else -import Data.Typeable (TyCon, mkTyCon, tyConString, typeOf) -#endif - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), showbParen, showbSpace) -import Text.Show.Text.Data.List () -import Text.Show.Text.Data.Typeable.Utils (showbArgs, showbTuple) -import Text.Show.Text.Utils (isTupleString) - -#include "inline.h" - --- | Convert a 'TypeRep' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbTypeRepPrec :: Int -> TypeRep -> Builder -showbTypeRepPrec p tyrep = - case tys of - [] -> showbTyCon tycon - [x] | tycon == listTc -> singleton '[' <> showb x <> singleton ']' - [a,r] | tycon == funTc -> showbParen (p > 8) $ - showbPrec 9 a - <> " -> " - <> showbPrec 8 r - xs | isTupleTyCon tycon -> showbTuple xs - | otherwise -> showbParen (p > 9) $ - showbPrec p tycon - <> showbSpace - <> showbArgs showbSpace -#if MIN_VERSION_base(4,8,0) - (kinds ++ tys) -#else - tys -#endif - where - tycon = typeRepTyCon tyrep - tys = typeRepArgs tyrep -#if MIN_VERSION_base(4,8,0) - kinds = typeRepKinds tyrep -#endif - -#if !(MIN_VERSION_base(4,4,0)) --- | The list 'TyCon'. -listTc :: TyCon -listTc = typeRepTyCon $ typeOf [()] - --- | The function (@->@) 'TyCon'. -funTc :: TyCon -funTc = mkTyCon "->" -#endif - --- | Does the 'TyCon' represent a tuple type constructor? -isTupleTyCon :: TyCon -> Bool -isTupleTyCon = isTupleString . tyConString -{-# INLINE isTupleTyCon #-} - --- | Convert a 'TyCon' to a 'Builder'. --- --- /Since: 0.3/ -showbTyCon :: TyCon -> Builder -showbTyCon = fromString . tyConString -{-# INLINE showbTyCon #-} - -#if MIN_VERSION_base(4,4,0) --- | Identical to 'tyConName'. Defined to avoid using excessive amounts of pragmas --- with base-4.3 and earlier, which use 'tyConString'. -tyConString :: TyCon -> String -tyConString = tyConName -{-# INLINE tyConString #-} -#endif - -instance Show TypeRep where - showbPrec = showbTypeRepPrec - INLINE_INST_FUN(showbPrec) - -instance Show TyCon where - showb = showbTyCon - INLINE_INST_FUN(showb)
− src/Text/Show/Text/Data/Typeable/Utils.hs
@@ -1,31 +0,0 @@-{-| -Module: Text.Show.Text.Data.Typeable.Utils -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Utility functions for showing data types in the @Typeable@ (or @OldTypeable@) module. --} -module Text.Show.Text.Data.Typeable.Utils (showbArgs, showbTuple) where - -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, singleton) - -import Prelude () -import Prelude.Compat hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec)) - --- | Helper function for showing a list of arguments, each separated by the given --- 'Builder'. -showbArgs :: Show a => Builder -> [a] -> Builder -showbArgs _ [] = mempty -showbArgs _ [a] = showbPrec 10 a -showbArgs sep (a:as) = showbPrec 10 a <> sep <> showbArgs sep as - --- | Helper function for showing a list of 'Show' instances in a tuple. -showbTuple :: Show a => [a] -> Builder -showbTuple args = singleton '(' <> showbArgs (singleton ',') args <> singleton ')' -{-# INLINE showbTuple #-}
− src/Text/Show/Text/Data/Version.hs
@@ -1,52 +0,0 @@-{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Version -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for 'Version'. - -/Since: 0.3/ --} -module Text.Show.Text.Data.Version ( - showbVersionPrec - , showbVersionConcrete - ) where - -import Data.List (intersperse) -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, fromString, singleton) -import Data.Version (Version(..)) - -import Prelude () -import Prelude.Compat - -import Text.Show.Text.Classes (showb, showbPrec) -import Text.Show.Text.Data.Char () -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Data.List () -import Text.Show.Text.TH.Internal (deriveShow) - --- | Convert a 'Version' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbVersionPrec :: Int -> Version -> Builder -showbVersionPrec = showbPrec -{-# INLINE showbVersionPrec #-} - --- | Provides one possible concrete representation for 'Version'. For --- a version with 'versionBranch' @= [1,2,3]@ and 'versionTags' --- @= [\"tag1\",\"tag2\"]@, the output will be @1.2.3-tag1-tag2@. --- --- /Since: 0.3/ -showbVersionConcrete :: Version -> Builder -showbVersionConcrete (Version branch tags) - = mconcat (intersperse (singleton '.') $ map showb branch) <> - mconcat (map ((singleton '-' <>) . fromString) tags) -{-# INLINE showbVersionConcrete #-} - -$(deriveShow ''Version)
− src/Text/Show/Text/Data/Void.hs
@@ -1,31 +0,0 @@-{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Data.Void -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Void' values. - -/Since: 0.5/ --} -module Text.Show.Text.Data.Void (showbVoid) where - -import Data.Text.Lazy.Builder (Builder) -import Data.Void (Void, absurd) - -import Prelude () - -import Text.Show.Text.Classes (Show(showb)) - --- | Since 'Void' values logically don't exist, attempting to convert one to a --- 'Builder' will never terminate. --- --- /Since: 0.5/ -showbVoid :: Void -> Builder -showbVoid = absurd - -instance Show Void where - showb = showbVoid
− src/Text/Show/Text/Debug/Trace.hs
@@ -1,368 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE ForeignFunctionInterface #-} -{-# LANGUAGE OverloadedStrings #-} -{-| -Module: Text.Show.Text.Debug.Trace -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Functions for tracing and monitoring execution. - -These can be useful for investigating bugs or performance problems. -They should /not/ be used in production code. - -If you do not wish to require 'Show' instances for your @trace@ functions, -the "Text.Show.Text.Debug.Trace.TH" and "Text.Show.Text.Debug.Trace.Generic" modules -exist to convert the input to a debug message using Template Haskell or generics, -respectively. - -/Since: 0.5/ --} -module Text.Show.Text.Debug.Trace ( - -- * Tracing - -- $tracing - trace - , traceLazy - , traceId - , traceIdLazy - , traceShow - , traceShowId -#if MIN_VERSION_base(4,5,0) - , traceStack - , traceStackLazy -#endif - , traceIO - , traceIOLazy - , traceM - , traceMLazy - , traceShowM - -#if MIN_VERSION_base(4,5,0) - -- * Eventlog tracing - -- $eventlog_tracing - , traceEvent - , traceEventLazy - , traceEventIO - , traceEventIOLazy -#endif -#if MIN_VERSION_base(4,7,0) - -- * Execution phase markers - -- $markers - , traceMarker - , traceMarkerLazy - , traceMarkerIO - , traceMarkerIOLazy -#endif - ) where - -import Control.Monad (unless) - -import qualified Data.ByteString as BS (null, partition) -import Data.ByteString (ByteString, useAsCString) -import Data.ByteString.Internal (c2w) -import qualified Data.Text as TS (Text) -import Data.Text.Encoding (encodeUtf8) -import qualified Data.Text.Lazy as TL (Text) -import Data.Text.Lazy (toStrict) - -import Foreign.C.String (CString) - -#if MIN_VERSION_base(4,5,0) -import qualified Data.ByteString.Char8 as BS (pack) -import qualified Data.Text as TS (unpack) -import qualified Data.Text.Lazy as TL (unpack) - -import qualified Debug.Trace as S - -import GHC.Stack (currentCallStack, renderStack) -#endif - -import Prelude hiding (Show(show)) - -import System.IO.Unsafe (unsafePerformIO) - -import Text.Show.Text.Classes (Show, show) -import Text.Show.Text.Instances () - --- $tracing --- --- The 'trace', 'traceShow' and 'traceIO' functions print messages to an output --- stream. They are intended for \"printf debugging\", that is: tracing the flow --- of execution and printing interesting values. --- --- All these functions evaluate the message completely before printing --- it; so if the message is not fully defined, none of it will be --- printed. --- --- The usual output stream is 'System.IO.stderr'. For Windows GUI applications --- (that have no stderr) the output is directed to the Windows debug console. --- Some implementations of these functions may decorate the @Text@ that\'s --- output to indicate that you\'re tracing. - --- | The 'traceIO' function outputs the trace message from the IO monad. --- This sequences the output with respect to other IO actions. --- --- /Since: 0.5/ -traceIO :: TS.Text -> IO () -traceIO = traceIOByteString . encodeUtf8 - --- | Like 'traceIO' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceIOLazy :: TL.Text -> IO () -traceIOLazy = traceIO . toStrict - -traceIOByteString :: ByteString -> IO () -traceIOByteString msg = useAsCString "%s\n" $ \cfmt -> do - -- NB: debugBelch can't deal with null bytes, so filter them - -- out so we don't accidentally truncate the message. See Trac #9395 - let (nulls, msg') = BS.partition (== c2w '\0') msg - useAsCString msg' $ \cmsg -> - debugBelch cfmt cmsg - unless (BS.null nulls) $ - useAsCString "WARNING: previous trace message had null bytes" $ \cmsg -> - debugBelch cfmt cmsg - --- don't use debugBelch() directly, because we cannot call varargs functions --- using the FFI. -foreign import ccall unsafe "HsBase.h debugBelch2" - debugBelch :: CString -> CString -> IO () - -{-| -The 'trace' function outputs the trace message given as its first argument, -before returning the second argument as its result. - -For example, this returns the value of @f x@ but first outputs the message. - -> trace ("calling f with x = " <> show x) (f x) - -The 'trace' function should /only/ be used for debugging, or for monitoring -execution. The function is not referentially transparent: its type indicates -that it is a pure function but it has the side effect of outputting the -trace message. - -/Since: 0.5/ --} -trace :: TS.Text -> a -> a -trace = traceByteString . encodeUtf8 - --- | Like 'trace' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceLazy :: TL.Text -> a -> a -traceLazy = trace . toStrict - -{-# NOINLINE traceByteString #-} -traceByteString :: ByteString -> a -> a -traceByteString bs expr = unsafePerformIO $ do - traceIOByteString bs - return expr - --- | Like 'trace' but returns the message instead of a third value. --- --- /Since: 0.5/ -traceId :: TS.Text -> TS.Text -traceId a = trace a a - --- | Like 'traceId' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceIdLazy :: TL.Text -> TL.Text -traceIdLazy a = traceLazy a a - -{-| -Like 'trace', but uses 'show' on the argument to convert it to a 'TS.Text'. - -This makes it convenient for printing the values of interesting variables or -expressions inside a function. For example here we print the value of the -variables @x@ and @z@: - -> f x y = -> traceShow (x, z) $ result -> where -> z = ... -> ... - -/Since: 0.5/ --} -traceShow :: Show a => a -> b -> b -traceShow = trace . show - --- | Like 'traceShow' but returns the shown value instead of a third value. --- --- /Since: 0.5/ -traceShowId :: Show a => a -> a -traceShowId a = trace (show a) a - -{-| -Like 'trace' but returning unit in an arbitrary monad. Allows for convenient -use in do-notation. Note that the application of 'trace' is not an action in the -monad, as 'traceIO' is in the 'IO' monad. - -> ... = do -> x <- ... -> traceM $ "x: " <> show x -> y <- ... -> traceM $ "y: " <> show y - -/Since: 0.5/ --} -traceM :: Monad m => TS.Text -> m () -traceM text = trace text $ return () - --- | Like 'traceM' but accepts a lazy 'TL.Text' argument. -traceMLazy :: Monad m => TL.Text -> m () -traceMLazy text = traceLazy text $ return () - -{-| -Like 'traceM', but uses 'show' on the argument to convert it to a 'TS.Text'. - -> ... = do -> x <- ... -> traceMShow $ x -> y <- ... -> traceMShow $ x + y - -/Since: 0.5/ --} -traceShowM :: (Show a, Monad m) => a -> m () -traceShowM = traceM . show - -#if MIN_VERSION_base(4,5,0) --- | Like 'trace' but additionally prints a call stack if one is --- available. --- --- In the current GHC implementation, the call stack is only --- availble if the program was compiled with @-prof@; otherwise --- 'traceStack' behaves exactly like 'trace'. Entries in the call --- stack correspond to @SCC@ annotations, so it is a good idea to use --- @-fprof-auto@ or @-fprof-auto-calls@ to add SCC annotations automatically. --- --- /Since: 0.5/ -traceStack :: TS.Text -> a -> a -traceStack = traceStackByteString . encodeUtf8 - --- | Like 'traceStack' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceStackLazy :: TL.Text -> a -> a -traceStackLazy = traceStack . toStrict - -traceStackByteString :: ByteString -> a -> a -traceStackByteString bs expr = unsafePerformIO $ do - traceIOByteString bs - stack <- currentCallStack - unless (null stack) . traceIOByteString . BS.pack $ renderStack stack - return expr - --- $eventlog_tracing --- --- Eventlog tracing is a performance profiling system. These functions emit --- extra events into the eventlog. In combination with eventlog profiling --- tools these functions can be used for monitoring execution and --- investigating performance problems. --- --- Currently only GHC provides eventlog profiling, see the GHC user guide for --- details on how to use it. These function exists for other Haskell --- implementations but no events are emitted. Note that the @Text@ message is --- always evaluated, whether or not profiling is available or enabled. - --- | The 'traceEvent' function behaves like 'trace' with the difference that --- the message is emitted to the eventlog, if eventlog profiling is available --- and enabled at runtime. --- --- It is suitable for use in pure code. In an IO context use 'traceEventIO' --- instead. --- --- Note that when using GHC's SMP runtime, it is possible (but rare) to get --- duplicate events emitted if two CPUs simultaneously evaluate the same thunk --- that uses 'traceEvent'. --- --- /Since: 0.5/ -traceEvent :: TS.Text -> a -> a -traceEvent = S.traceEvent . TS.unpack - --- | Like 'traceEvent' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceEventLazy :: TL.Text -> a -> a -traceEventLazy = S.traceEvent . TL.unpack - --- | The 'traceEventIO' function emits a message to the eventlog, if eventlog --- profiling is available and enabled at runtime. --- --- Compared to 'traceEvent', 'traceEventIO' sequences the event with respect to --- other IO actions. --- --- /Since: 0.5/ -traceEventIO :: TS.Text -> IO () -traceEventIO = S.traceEventIO . TS.unpack - --- | Like 'traceEventIO' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceEventIOLazy :: TL.Text -> IO () -traceEventIOLazy = S.traceEventIO . TL.unpack -#endif - -#if MIN_VERSION_base(4,7,0) --- $markers --- --- When looking at a profile for the execution of a program we often want to --- be able to mark certain points or phases in the execution and see that --- visually in the profile. - --- For example, a program might have several distinct phases with different --- performance or resource behaviour in each phase. To properly interpret the --- profile graph we really want to see when each phase starts and ends. --- --- Markers let us do this: we can annotate the program to emit a marker at --- an appropriate point during execution and then see that in a profile. --- --- Currently this feature is only supported in GHC by the eventlog tracing --- system, but in future it may also be supported by the heap profiling or --- other profiling tools. These function exists for other Haskell --- implementations but they have no effect. Note that the @Text@ message is --- always evaluated, whether or not profiling is available or enabled. - --- | The 'traceMarker' function emits a marker to the eventlog, if eventlog --- profiling is available and enabled at runtime. The 'TS.Text' is the name of --- the marker. The name is just used in the profiling tools to help you keep --- clear which marker is which. --- --- This function is suitable for use in pure code. In an IO context use --- 'traceMarkerIO' instead. --- --- Note that when using GHC's SMP runtime, it is possible (but rare) to get --- duplicate events emitted if two CPUs simultaneously evaluate the same thunk --- that uses 'traceMarker'. --- --- /Since: 0.5/ -traceMarker :: TS.Text -> a -> a -traceMarker msg = S.traceMarker $ TS.unpack msg - --- | Like 'traceMarker' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceMarkerLazy :: TL.Text -> a -> a -traceMarkerLazy msg = S.traceMarker $ TL.unpack msg - --- | The 'traceMarkerIO' function emits a marker to the eventlog, if eventlog --- profiling is available and enabled at runtime. --- --- Compared to 'traceMarker', 'traceMarkerIO' sequences the event with respect to --- other IO actions. --- --- /Since: 0.5/ -traceMarkerIO :: TS.Text -> IO () -traceMarkerIO = S.traceMarkerIO . TS.unpack - --- | Like 'traceMarkerIO' but accepts a lazy 'TL.Text' argument. --- --- /Since: 0.5/ -traceMarkerIOLazy :: TL.Text -> IO () -traceMarkerIOLazy = S.traceMarkerIO . TL.unpack -#endif
− src/Text/Show/Text/Debug/Trace/Generic.hs
@@ -1,43 +0,0 @@-{-# LANGUAGE FlexibleContexts #-} - -{-| -Module: Text.Show.Text.Debug.Trace.Generic -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Functions that trace the values of 'Generic' instances (even if they are not -instances of @Show@). - -/Since: 0.6/ --} -module Text.Show.Text.Debug.Trace.Generic ( - genericTraceShow - , genericTraceShowId - , genericTraceShowM - ) where - -import Generics.Deriving.Base (Generic, Rep) - -import Text.Show.Text.Debug.Trace -import Text.Show.Text.Generic (GShow, genericShow) - --- | A 'Generic' implementation of 'traceShow'. --- --- /Since: 0.6/ -genericTraceShow :: (Generic a, GShow (Rep a)) => a -> b -> b -genericTraceShow = trace . genericShow - --- | A 'Generic' implementation of 'traceShowId'. --- --- /Since: 0.6/ -genericTraceShowId :: (Generic a, GShow (Rep a)) => a -> a -genericTraceShowId a = trace (genericShow a) a - --- | A 'Generic' implementation of 'traceShowM'. --- --- /Since: 0.6/ -genericTraceShowM :: (Generic a, GShow (Rep a), Monad m) => a -> m () -genericTraceShowM = traceM . genericShow
− src/Text/Show/Text/Debug/Trace/TH.hs
@@ -1,46 +0,0 @@-{-# LANGUAGE TemplateHaskell #-} -{-| -Module: Text.Show.Text.Debug.Trace.TH -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Functions that splice traces into source code which take an arbitrary data type or -data family instance as an argument (even if it is not an instance of @Show@). You -need to enable the @TemplateHaskell@ language extension in order to use this module. - -/Since: 0.5/ --} -module Text.Show.Text.Debug.Trace.TH ( - mkTraceShow - , mkTraceShowId - , mkTraceShowM - ) where - -import Language.Haskell.TH.Syntax (Name, Q, Exp) - -import Text.Show.Text.Debug.Trace -import Text.Show.Text.TH.Internal (mkShow) - --- | Generates a lambda expression which behaves like 'traceShow' (without requiring a --- @Show@ instance). --- --- /Since: 0.5/ -mkTraceShow :: Name -> Q Exp -mkTraceShow name = [| trace . $(mkShow name) |] - --- | Generates a lambda expression which behaves like 'traceShowId' (without requiring a --- @Show@ instance). --- --- /Since: 0.5/ -mkTraceShowId :: Name -> Q Exp -mkTraceShowId name = [| \a -> trace ($(mkShow name) a) a |] - --- | Generates a lambda expression which behaves like 'traceShowM' (without requiring a --- @Show@ instance). --- --- /Since: 0.5/ -mkTraceShowM :: Name -> Q Exp -mkTraceShowM name = [| traceM . $(mkShow name) |]
− src/Text/Show/Text/Foreign/C/Types.hs
@@ -1,479 +0,0 @@-{-# LANGUAGE CPP #-} -#if MIN_VERSION_base(4,5,0) -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE StandaloneDeriving #-} -#endif -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Foreign.C.Types -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for Haskell newtypes corresponding to C -types in the Foreign Function Interface (FFI). - -/Since: 0.3/ --} -module Text.Show.Text.Foreign.C.Types ( - showbCCharPrec - , showbCSCharPrec - , showbCUChar - , showbCShortPrec - , showbCUShort - , showbCIntPrec - , showbCUInt - , showbCLongPrec - , showbCULong - , showbCPtrdiffPrec - , showbCSize - , showbCWcharPrec - , showbCSigAtomicPrec - , showbCLLongPrec - , showbCULLong - , showbCIntPtrPrec - , showbCUIntPtr - , showbCIntMaxPrec - , showbCUIntMax - , showbCClockPrec - , showbCTimePrec -#if MIN_VERSION_base(4,4,0) - , showbCUSeconds - , showbCSUSecondsPrec -#endif - , showbCFloatPrec - , showbCDoublePrec - ) where - -import Data.Text.Lazy.Builder (Builder) - -import Foreign.C.Types - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec)) -import Text.Show.Text.Data.Floating () -import Text.Show.Text.Data.Integral () - -#if !(MIN_VERSION_base(4,5,0)) -import Data.Int -import Data.Word - -import Unsafe.Coerce (unsafeCoerce) - -# include "HsBaseConfig.h" -# include "inline.h" -#endif - --- | Convert a 'CChar' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCCharPrec :: Int -> CChar -> Builder -#if MIN_VERSION_base(4,5,0) -showbCCharPrec = showbPrec -{-# INLINE showbCCharPrec #-} -#else -showbCCharPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_CHAR -> Builder) -#endif - --- | Convert a 'CSChar' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCSCharPrec :: Int -> CSChar -> Builder -#if MIN_VERSION_base(4,5,0) -showbCSCharPrec = showbPrec -{-# INLINE showbCSCharPrec #-} -#else -showbCSCharPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SIGNED_CHAR -> Builder) -#endif - --- | Convert a 'CUChar' to a 'Builder'. --- --- /Since: 0.3/ -showbCUChar :: CUChar -> Builder -#if MIN_VERSION_base(4,5,0) -showbCUChar = showb -{-# INLINE showbCUChar #-} -#else -showbCUChar = unsafeCoerce (showb :: HTYPE_UNSIGNED_CHAR -> Builder) -#endif - --- | Convert a 'CShort' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCShortPrec :: Int -> CShort -> Builder -#if MIN_VERSION_base(4,5,0) -showbCShortPrec = showbPrec -{-# INLINE showbCShortPrec #-} -#else -showbCShortPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SHORT -> Builder) -#endif - --- | Convert a 'CUShort' to a 'Builder'. --- --- /Since: 0.3/ -showbCUShort :: CUShort -> Builder -#if MIN_VERSION_base(4,5,0) -showbCUShort = showb -{-# INLINE showbCUShort #-} -#else -showbCUShort = unsafeCoerce (showb :: HTYPE_UNSIGNED_SHORT -> Builder) -#endif - --- | Convert a 'CInt' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCIntPrec :: Int -> CInt -> Builder -#if MIN_VERSION_base(4,5,0) -showbCIntPrec = showbPrec -{-# INLINE showbCIntPrec #-} -#else -showbCIntPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_INT -> Builder) -#endif - --- | Convert a 'CUInt' to a 'Builder'. --- --- /Since: 0.3/ -showbCUInt :: CUInt -> Builder -#if MIN_VERSION_base(4,5,0) -showbCUInt = showb -{-# INLINE showbCUInt #-} -#else -showbCUInt = unsafeCoerce (showb :: HTYPE_UNSIGNED_INT -> Builder) -#endif - --- | Convert a 'CLong' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCLongPrec :: Int -> CLong -> Builder -#if MIN_VERSION_base(4,5,0) -showbCLongPrec = showbPrec -{-# INLINE showbCLongPrec #-} -#else -showbCLongPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_LONG -> Builder) -#endif - --- | Convert a 'CULong' to a 'Builder'. --- --- /Since: 0.3/ -showbCULong :: CULong -> Builder -#if MIN_VERSION_base(4,5,0) -showbCULong = showb -{-# INLINE showbCULong #-} -#else -showbCULong = unsafeCoerce (showb :: HTYPE_UNSIGNED_LONG -> Builder) -#endif - --- | Convert a 'CPtrdiff' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCPtrdiffPrec :: Int -> CPtrdiff -> Builder -#if MIN_VERSION_base(4,5,0) -showbCPtrdiffPrec = showbPrec -{-# INLINE showbCPtrdiffPrec #-} -#else -showbCPtrdiffPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_PTRDIFF_T -> Builder) -#endif - --- | Convert a 'CSize' to a 'Builder'. --- --- /Since: 0.3/ -showbCSize :: CSize -> Builder -#if MIN_VERSION_base(4,5,0) -showbCSize = showb -{-# INLINE showbCSize #-} -#else -showbCSize = unsafeCoerce (showb :: HTYPE_SIZE_T -> Builder) -#endif - --- | Convert a 'CWchar' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCWcharPrec :: Int -> CWchar -> Builder -#if MIN_VERSION_base(4,5,0) -showbCWcharPrec = showbPrec -{-# INLINE showbCWcharPrec #-} -#else -showbCWcharPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_WCHAR_T -> Builder) -#endif - --- | Convert a 'CSigAtomic' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCSigAtomicPrec :: Int -> CSigAtomic -> Builder -#if MIN_VERSION_base(4,5,0) -showbCSigAtomicPrec = showbPrec -{-# INLINE showbCSigAtomicPrec #-} -#else -showbCSigAtomicPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SIG_ATOMIC_T -> Builder) -#endif - --- | Convert a 'CLLong' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCLLongPrec :: Int -> CLLong -> Builder -#if MIN_VERSION_base(4,5,0) -showbCLLongPrec = showbPrec -{-# INLINE showbCLLongPrec #-} -#else -showbCLLongPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_LONG_LONG -> Builder) -#endif - --- | Convert a 'CULLong' to a 'Builder'. --- --- /Since: 0.3/ -showbCULLong :: CULLong -> Builder -#if MIN_VERSION_base(4,5,0) -showbCULLong = showb -{-# INLINE showbCULLong #-} -#else -showbCULLong = unsafeCoerce (showb :: HTYPE_UNSIGNED_LONG_LONG -> Builder) -#endif - --- | Convert a 'CIntPtr' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCIntPtrPrec :: Int -> CIntPtr -> Builder -#if MIN_VERSION_base(4,5,0) -showbCIntPtrPrec = showbPrec -{-# INLINE showbCIntPtrPrec #-} -#else -showbCIntPtrPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_INTPTR_T -> Builder) -#endif - --- | Convert a 'CUIntPtr' to a 'Builder'. --- --- /Since: 0.3/ -showbCUIntPtr :: CUIntPtr -> Builder -#if MIN_VERSION_base(4,5,0) -showbCUIntPtr = showb -{-# INLINE showbCUIntPtr #-} -#else -showbCUIntPtr = unsafeCoerce (showb :: HTYPE_UINTPTR_T -> Builder) -#endif - --- | Convert a 'CIntMax' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCIntMaxPrec :: Int -> CIntMax -> Builder -#if MIN_VERSION_base(4,5,0) -showbCIntMaxPrec = showbPrec -{-# INLINE showbCIntMaxPrec #-} -#else -showbCIntMaxPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_INTMAX_T -> Builder) -#endif - --- | Convert a 'CUIntMax' to a 'Builder'. --- --- /Since: 0.3/ -showbCUIntMax :: CUIntMax -> Builder -#if MIN_VERSION_base(4,5,0) -showbCUIntMax = showb -{-# INLINE showbCUIntMax #-} -#else -showbCUIntMax = unsafeCoerce (showb :: HTYPE_UINTMAX_T -> Builder) -#endif - --- | Convert a 'CClock' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCClockPrec :: Int -> CClock -> Builder -#if MIN_VERSION_base(4,5,0) -showbCClockPrec = showbPrec -{-# INLINE showbCClockPrec #-} -#else -showbCClockPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_CLOCK_T -> Builder) -#endif - --- | Convert a 'CTime' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCTimePrec :: Int -> CTime -> Builder -#if MIN_VERSION_base(4,5,0) -showbCTimePrec = showbPrec -{-# INLINE showbCTimePrec #-} -#else -showbCTimePrec = unsafeCoerce (showbPrec :: Int -> HTYPE_TIME_T -> Builder) -#endif - -#if MIN_VERSION_base(4,4,0) --- | Convert a 'CUSeconds' value to a 'Builder'. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 0.3/ -showbCUSeconds :: CUSeconds -> Builder -# if MIN_VERSION_base(4,5,0) -showbCUSeconds = showb -{-# INLINE showbCUSeconds #-} -# else -showbCUSeconds = unsafeCoerce (showb :: HTYPE_USECONDS_T -> Builder) -# endif - --- | Convert a 'CSUSeconds' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 0.3/ -showbCSUSecondsPrec :: Int -> CSUSeconds -> Builder -# if MIN_VERSION_base(4,5,0) -showbCSUSecondsPrec = showbPrec -{-# INLINE showbCSUSecondsPrec #-} -# else -showbCSUSecondsPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SUSECONDS_T -> Builder) -# endif -#endif - --- | Convert a 'CFloat' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCFloatPrec :: Int -> CFloat -> Builder -#if MIN_VERSION_base(4,5,0) -showbCFloatPrec = showbPrec -{-# INLINE showbCFloatPrec #-} -#else -showbCFloatPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_FLOAT -> Builder) -#endif - --- | Convert a 'CDouble' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCDoublePrec :: Int -> CDouble -> Builder -#if MIN_VERSION_base(4,5,0) -showbCDoublePrec = showbPrec -{-# INLINE showbCDoublePrec #-} -#else -showbCDoublePrec = unsafeCoerce (showbPrec :: Int -> HTYPE_DOUBLE -> Builder) -#endif - -#if MIN_VERSION_base(4,5,0) -deriving instance Show CChar -deriving instance Show CSChar -deriving instance Show CUChar -deriving instance Show CShort -deriving instance Show CUShort -deriving instance Show CInt -deriving instance Show CUInt -deriving instance Show CLong -deriving instance Show CULong -deriving instance Show CPtrdiff -deriving instance Show CSize -deriving instance Show CWchar -deriving instance Show CSigAtomic -deriving instance Show CLLong -deriving instance Show CULLong -deriving instance Show CIntPtr -deriving instance Show CUIntPtr -deriving instance Show CIntMax -deriving instance Show CUIntMax -deriving instance Show CClock -deriving instance Show CTime -# if MIN_VERSION_base(4,4,0) -deriving instance Show CUSeconds -deriving instance Show CSUSeconds -# endif -deriving instance Show CFloat -deriving instance Show CDouble -#else -instance Show CChar where - showbPrec = showbCCharPrec - INLINE_INST_FUN(showbPrec) - -instance Show CSChar where - showbPrec = showbCSCharPrec - INLINE_INST_FUN(showbPrec) - -instance Show CUChar where - showb = showbCUChar - INLINE_INST_FUN(showb) - -instance Show CShort where - showbPrec = showbCShortPrec - INLINE_INST_FUN(showbPrec) - -instance Show CUShort where - showb = showbCUShort - INLINE_INST_FUN(showb) - -instance Show CInt where - showbPrec = showbCIntPrec - INLINE_INST_FUN(showbPrec) - -instance Show CUInt where - showb = showbCUInt - INLINE_INST_FUN(showb) - -instance Show CLong where - showbPrec = showbCLongPrec - INLINE_INST_FUN(showbPrec) - -instance Show CULong where - showb = showbCULong - INLINE_INST_FUN(showb) - -instance Show CPtrdiff where - showbPrec = showbCPtrdiffPrec - INLINE_INST_FUN(showbPrec) - -instance Show CSize where - showb = showbCSize - INLINE_INST_FUN(showb) - -instance Show CWchar where - showbPrec = showbCWcharPrec - INLINE_INST_FUN(showbPrec) - -instance Show CSigAtomic where - showbPrec = showbCSigAtomicPrec - INLINE_INST_FUN(showbPrec) - -instance Show CLLong where - showbPrec = showbCLLongPrec - INLINE_INST_FUN(showbPrec) - -instance Show CULLong where - showb = showbCULLong - INLINE_INST_FUN(showb) - -instance Show CIntPtr where - showbPrec = showbCIntPtrPrec - INLINE_INST_FUN(showbPrec) - -instance Show CUIntPtr where - showb = showbCUIntPtr - INLINE_INST_FUN(showb) - -instance Show CIntMax where - showbPrec = showbCIntMaxPrec - INLINE_INST_FUN(showbPrec) - -instance Show CUIntMax where - showb = showbCUIntMax - INLINE_INST_FUN(showb) - -instance Show CClock where - showbPrec = showbCClockPrec - INLINE_INST_FUN(showbPrec) - -instance Show CTime where - showbPrec = showbCTimePrec - INLINE_INST_FUN(showbPrec) - -# if MIN_VERSION_base(4,4,0) -instance Show CUSeconds where - showb = showbCUSeconds - INLINE_INST_FUN(showb) - -instance Show CSUSeconds where - showbPrec = showbCSUSecondsPrec - INLINE_INST_FUN(showbPrec) -# endif - -instance Show CFloat where - showbPrec = showbCFloatPrec - INLINE_INST_FUN(showbPrec) - -instance Show CDouble where - showbPrec = showbCDoublePrec - INLINE_INST_FUN(showbPrec) -#endif
− src/Text/Show/Text/Foreign/Ptr.hs
@@ -1,117 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE MagicHash #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Foreign.Ptr -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for pointer types used in the Haskell -Foreign Function Interface (FFI). - -/Since: 0.3/ --} -module Text.Show.Text.Foreign.Ptr ( - showbPtr - , showbFunPtr - , showbIntPtrPrec - , showbWordPtr - , showbForeignPtr - ) where - -import Data.Monoid.Compat ((<>)) -import Data.Semigroup (timesN) -import Data.Text.Lazy.Builder (Builder, singleton) - -import Foreign.ForeignPtr (ForeignPtr) -import Foreign.Ptr (FunPtr, IntPtr, WordPtr, castFunPtrToPtr) - -import GHC.ForeignPtr (unsafeForeignPtrToPtr) -import GHC.Num (wordToInteger) -import GHC.Ptr (Ptr(..)) -import GHC.Prim (addr2Int#, int2Word#, unsafeCoerce#) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), Show1(..)) -import Text.Show.Text.Data.Integral (showbHex, showbIntPrec, showbWord) -import Text.Show.Text.Utils (lengthB) - -#include "MachDeps.h" -#include "inline.h" - --- | Convert a 'Ptr' to a 'Builder'. Note that this does not require the parameterized --- type to be an instance of 'Show' itself. --- --- /Since: 0.3/ -showbPtr :: Ptr a -> Builder -showbPtr = showb -{-# INLINE showbPtr #-} - --- | Convert a 'FunPtr' to a 'Builder'. Note that this does not require the --- parameterized type to be an instance of 'Show' itself. --- --- /Since: 0.3/ -showbFunPtr :: FunPtr a -> Builder -showbFunPtr = showb -{-# INLINE showbFunPtr #-} - --- | Convert an 'IntPtr' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbIntPtrPrec :: Int -> IntPtr -> Builder -showbIntPtrPrec p ip = showbIntPrec p $ unsafeCoerce# ip - --- | Convert a 'WordPtr' to a 'Builder'. --- --- /Since: 0.3/ -showbWordPtr :: WordPtr -> Builder -showbWordPtr wp = showbWord $ unsafeCoerce# wp - --- | Convert a 'ForeignPtr' to a 'Builder'. Note that this does not require the --- parameterized type to be an instance of 'Show' itself. --- --- /Since: 0.3/ -showbForeignPtr :: ForeignPtr a -> Builder -showbForeignPtr = showb -{-# INLINE showbForeignPtr #-} - -instance Show (Ptr a) where - showbPrec = showbPrecWith undefined - INLINE_INST_FUN(showb) - -instance Show1 Ptr where - showbPrecWith _ _ (Ptr a) = padOut . showbHex $ wordToInteger (int2Word# (addr2Int# a)) - where - padOut :: Builder -> Builder - padOut ls = - singleton '0' <> singleton 'x' - <> timesN (fromIntegral . max 0 $ 2*SIZEOF_HSPTR - lengthB ls) (singleton '0') - <> ls - -instance Show (FunPtr a) where - showbPrec = showbPrecWith undefined - INLINE_INST_FUN(showb) - -instance Show1 FunPtr where - showbPrecWith _ _ = showb . castFunPtrToPtr - INLINE_INST_FUN(showbPrecWith) - -instance Show IntPtr where - showbPrec = showbIntPtrPrec - INLINE_INST_FUN(showbPrec) - -instance Show WordPtr where - showb = showbWordPtr - INLINE_INST_FUN(showb) - -instance Show (ForeignPtr a) where - showbPrec = showbPrecWith undefined - INLINE_INST_FUN(showb) - -instance Show1 ForeignPtr where - showbPrecWith _ _ = showb . unsafeForeignPtrToPtr - INLINE_INST_FUN(showbPrecWith)
− src/Text/Show/Text/Functions.hs
@@ -1,41 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Functions -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Optional 'Show', 'Show1', and 'Show2' instances for functions. - -/Since: 0.3/ --} -module Text.Show.Text.Functions (showbFunction) where - -import Data.Text.Lazy.Builder (Builder) -import Prelude hiding (Show) -import Text.Show.Text.Classes (Show(showb, showbPrec), Show1(..), Show2(..)) - -#include "inline.h" - --- | Convert a function to a 'Builder'. --- --- /Since: 0.3/ -showbFunction :: (a -> b) -> Builder -showbFunction = showb -{-# INLINE showbFunction #-} - -instance Show (a -> b) where - showbPrec = showbPrecWith undefined - INLINE_INST_FUN(showb) - -instance Show1 ((->) a) where - showbPrecWith = showbPrecWith2 undefined - INLINE_INST_FUN(showbPrecWith) - -instance Show2 (->) where - showbPrecWith2 _ _ _ _ = "<function>" - INLINE_INST_FUN(showbPrecWith2)
− src/Text/Show/Text/GHC/Conc/Windows.hs
@@ -1,42 +0,0 @@-{-# LANGUAGE CPP #-} - -#if !defined(__GHCJS__) && defined(mingw32_HOST_OS) -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.Conc.Windows -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'ConsoleEvent'. -This module only exports functions if using Windows, and not using GHCJS. - -/Since: 0.5/ --} -module Text.Show.Text.GHC.Conc.Windows ( -#if defined(__GHCJS__) || !defined(mingw32_HOST_OS) - ) where -#else - showbConsoleEvent - ) where - -import Data.Text.Lazy.Builder (Builder) - -import GHC.Conc.Windows (ConsoleEvent) - -import Text.Show.Text.Classes (showb) -import Text.Show.Text.TH.Internal (deriveShow) - --- | Convert a 'ConsoleEvent' to a 'Builder'. --- --- /Since: 0.5/ -showbConsoleEvent :: ConsoleEvent -> Builder -showbConsoleEvent = showb -{-# INLINE showbConsoleEvent #-} - -$(deriveShow ''ConsoleEvent) -#endif
− src/Text/Show/Text/GHC/Event.hs
@@ -1,58 +0,0 @@-{-# LANGUAGE CPP #-} - -#if !defined(__GHCJS__) && !defined(mingw32_HOST_OS) && MIN_VERSION_base(4,4,0) -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.Event -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the @Event@ module. -This module only exports functions if using @base-4.4.0.0@ on a platform other -than Windows or GHCJS. - -/Since: 0.3/ --} -module Text.Show.Text.GHC.Event ( -#if defined(__GHCJS__) || defined(mingw32_HOST_OS) || !(MIN_VERSION_base(4,4,0)) - ) where -#else - showbEvent - , showbFdKeyPrec - ) where - -import Data.Text.Lazy.Builder (Builder) -import GHC.Event (Event, FdKey) -import Prelude hiding (Show) -import Text.Show.Text.Classes (Show(showb, showbPrec), FromStringShow(..)) - --- | Convert an 'Event' to a 'Builder'. --- This function is only available with @base-4.4.0.0@ or later and is not available --- on Windows. --- --- /Since: 0.3/ -showbEvent :: Event -> Builder -showbEvent = showb . FromStringShow -{-# INLINE showbEvent #-} - --- | Convert an 'FdKey' to a 'Builder' with the given precedence. --- This function is only available with @base-4.4.0.0@ or later and is not available --- on Windows. --- --- /Since: 0.3/ -showbFdKeyPrec :: Int -> FdKey -> Builder -showbFdKeyPrec p = showbPrec p . FromStringShow -{-# INLINE showbFdKeyPrec #-} - -instance Show Event where - showb = showbEvent - {-# INLINE showb #-} - -instance Show FdKey where - showbPrec = showbFdKeyPrec - {-# INLINE showbPrec #-} -#endif
− src/Text/Show/Text/GHC/Fingerprint.hs
@@ -1,53 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,4,0) -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.Fingerprint -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Fingerprint' values. -This module only exports functions if using @base-4.4.0.0@ or later. - -/Since: 0.5/ --} -module Text.Show.Text.GHC.Fingerprint ( -#if !(MIN_VERSION_base(4,4,0)) - ) where -#else - showbFingerprint - ) where - -import Data.Monoid.Compat ((<>)) -import Data.Semigroup (timesN) -import Data.Text.Lazy.Builder (Builder, singleton) -import Data.Word (Word64) - -import GHC.Fingerprint.Type (Fingerprint(..)) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb)) -import Text.Show.Text.Data.Integral (showbHex) -import Text.Show.Text.Utils (lengthB) - --- | Convert a 'Fingerprint' to a 'Builder'. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 0.5/ -showbFingerprint :: Fingerprint -> Builder -showbFingerprint (Fingerprint w1 w2) = hex16 w1 <> hex16 w2 - where - hex16 :: Word64 -> Builder - hex16 i = let hex = showbHex i - in timesN (fromIntegral . max 0 $ 16 - lengthB hex) (singleton '0') <> hex - -instance Show Fingerprint where - showb = showbFingerprint - {-# INLINE showb #-} -#endif
− src/Text/Show/Text/GHC/Generics.hs
@@ -1,201 +0,0 @@-{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeOperators #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - -{-| -Module: Text.Show.Text.GHC.Generics -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for generics-related data types. - -/Since: 0.3/ --} -module Text.Show.Text.GHC.Generics ( - showbU1 - , showbPar1PrecWith - , showbRec1Prec - , showbRec1PrecWith - , showbK1PrecWith - , showbM1Prec - , showbM1PrecWith - , showbSumTypePrec - , showbSumTypePrecWith - , showbProductTypePrec - , showbProductTypePrecWith - , showbCompFunctorsPrec - , showbCompFunctorsPrecWith - , showbFixityPrec - , showbAssociativity - , showbArityPrec - ) where - -import Data.Text.Lazy.Builder (Builder) - -import Generics.Deriving.Base (U1(..), Par1, Rec1(..), K1(..), - M1(..), (:+:)(..), (:*:)(..), (:.:)(..), - Fixity, Associativity, Arity) - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), Show1(..), Show2(..)) -import Text.Show.Text.Data.Integral () -import Text.Show.Text.TH.Internal (deriveShow, deriveShow1, mkShowbPrec, - mkShowbPrecWith, mkShowbPrecWith2) - --- | Convert a 'U1' value to a 'Builder'. --- --- /Since: 0.3/ -showbU1 :: U1 p -> Builder -showbU1 = showb -{-# INLINE showbU1 #-} - --- | Convert a 'Par1' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbPar1PrecWith :: (Int -> p -> Builder) -> Int -> Par1 p -> Builder -showbPar1PrecWith = showbPrecWith -{-# INLINE showbPar1PrecWith #-} - --- | Convert a 'Rec1' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbRec1Prec :: Show (f p) => Int -> Rec1 f p -> Builder -showbRec1Prec = showbPrec -{-# INLINE showbRec1Prec #-} - --- | Convert a 'Rec1' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbRec1PrecWith :: Show1 f => (Int -> p -> Builder) -> Int -> Rec1 f p -> Builder -showbRec1PrecWith = showbPrecWith -{-# INLINE showbRec1PrecWith #-} - --- | Convert a 'K1' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbK1PrecWith :: (Int -> c -> Builder) -> Int -> K1 i c p -> Builder -showbK1PrecWith sp = showbPrecWith2 sp undefined -{-# INLINE showbK1PrecWith #-} - --- | Convert an 'M1' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbM1Prec :: Show (f p) => Int -> M1 i c f p -> Builder -showbM1Prec = showbPrec -{-# INLINE showbM1Prec #-} - --- | Convert an 'M1' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbM1PrecWith :: Show1 f => (Int -> p -> Builder) -> Int -> M1 i c f p -> Builder -showbM1PrecWith = showbPrecWith -{-# INLINE showbM1PrecWith #-} - --- | Convert a '(:+:)' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbSumTypePrec :: (Show (f p), Show (g p)) => Int -> (f :+: g) p -> Builder -showbSumTypePrec = showbPrec -{-# INLINE showbSumTypePrec #-} - --- | Convert a '(:+:)' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbSumTypePrecWith :: (Show1 f, Show1 g) => (Int -> p -> Builder) -> Int -> (f :+: g) p -> Builder -showbSumTypePrecWith = showbPrecWith -{-# INLINE showbSumTypePrecWith #-} - --- | Convert a '(:*:)' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbProductTypePrec :: (Show (f p), Show (g p)) => Int -> (f :*: g) p -> Builder -showbProductTypePrec = showbPrec -{-# INLINE showbProductTypePrec #-} - --- | Convert a '(:*:)' value to a 'Builder' with the given show function and precedence. --- --- /Since: 1/ -showbProductTypePrecWith :: (Show1 f, Show1 g) => (Int -> p -> Builder) -> Int -> (f :*: g) p -> Builder -showbProductTypePrecWith = showbPrecWith -{-# INLINE showbProductTypePrecWith #-} - --- | Convert a '(:.:)' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCompFunctorsPrec :: Show (f (g p)) => Int -> (f :.: g) p -> Builder -showbCompFunctorsPrec = showbPrec -{-# INLINE showbCompFunctorsPrec #-} - --- | Convert a '(:.:)' value to a 'Builder' with the given show function and precedence. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 1/ -showbCompFunctorsPrecWith :: (Show1 f, Show1 g) => (Int -> p -> Builder) -> Int -> (f :.: g) p -> Builder -showbCompFunctorsPrecWith = showbPrecWith -{-# INLINE showbCompFunctorsPrecWith #-} - --- | Convert a 'Fixity' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbFixityPrec :: Int -> Fixity -> Builder -showbFixityPrec = showbPrec -{-# INLINE showbFixityPrec #-} - --- | Convert an 'Associativity' value to a 'Builder'. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 0.3/ -showbAssociativity :: Associativity -> Builder -showbAssociativity = showb -{-# INLINE showbAssociativity #-} - --- | Convert an 'Arity' value to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbArityPrec :: Int -> Arity -> Builder -showbArityPrec = showbPrec -{-# INLINE showbArityPrec #-} - -instance Show (U1 p) where - showbPrec = showbPrecWith undefined -$(deriveShow1 ''U1) - -$(deriveShow ''Par1) -$(deriveShow1 ''Par1) - -instance Show (f p) => Show (Rec1 f p) where - showbPrec = $(mkShowbPrec ''Rec1) -$(deriveShow1 ''Rec1) - -instance Show c => Show (K1 i c p) where - showbPrec = showbPrecWith undefined -instance Show c => Show1 (K1 i c) where - showbPrecWith = showbPrecWith2 showbPrec -instance Show2 (K1 i) where - showbPrecWith2 = $(mkShowbPrecWith2 ''K1) - -instance Show (f p) => Show (M1 i c f p) where - showbPrec = $(mkShowbPrec ''M1) -instance Show1 f => Show1 (M1 i c f) where - showbPrecWith = $(mkShowbPrecWith ''M1) - -instance (Show (f p), Show (g p)) => Show ((f :+: g) p) where - showbPrec = $(mkShowbPrec ''(:+:)) -$(deriveShow1 ''(:+:)) - -instance (Show (f p), Show (g p)) => Show ((f :*: g) p) where - showbPrec = $(mkShowbPrec ''(:*:)) -$(deriveShow1 ''(:*:)) - -instance Show (f (g p)) => Show ((f :.: g) p) where - showbPrec = $(mkShowbPrec ''(:.:)) -$(deriveShow1 ''(:.:)) - -$(deriveShow ''Fixity) -$(deriveShow ''Associativity) -$(deriveShow ''Arity)
− src/Text/Show/Text/GHC/RTS/Flags.hs
@@ -1,267 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,8,0) -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.RTS.Flags -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the 'GHC.RTS.Flags' module. -This module only exports functions if using @base-4.8.0.0@ or later. - -/Since: 0.5/ --} -module Text.Show.Text.GHC.RTS.Flags ( -#if !(MIN_VERSION_base(4,8,0)) - ) where -#else - showbRTSFlagsPrec - , showbGCFlagsPrec - , showbConcFlagsPrec - , showbMiscFlagsPrec - , showbDebugFlagsPrec - , showbCCFlagsPrec - , showbProfFlagsPrec - , showbTraceFlagsPrec - , showbTickyFlagsPrec - ) where - -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, singleton) - -import GHC.RTS.Flags - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showb, showbPrec), FromStringShow(..)) -import Text.Show.Text.Data.Bool (showbBool) -import Text.Show.Text.Data.Char () -import Text.Show.Text.Data.Floating (showbDoublePrec) -import Text.Show.Text.Data.Integral (showbIntPrec, showbWord, showbWord64) -import Text.Show.Text.Data.List () -import Text.Show.Text.Data.Maybe (showbMaybePrecWith) -import Text.Show.Text.TH.Internal (deriveShow) - -# if __GLASGOW_HASKELL__ < 711 -import GHC.Show (appPrec) -import Text.Show.Text.Classes (showbParen) -# endif - --- | Convert an 'RTSFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbRTSFlagsPrec :: Int -> RTSFlags -> Builder -showbRTSFlagsPrec = showbPrec -{-# INLINE showbRTSFlagsPrec #-} - --- | Convert a 'GCFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbGCFlagsPrec :: Int -> GCFlags -> Builder -# if __GLASGOW_HASKELL__ >= 711 -showbGCFlagsPrec _ gcfs = -# else -showbGCFlagsPrec p gcfs = showbParen (p > appPrec) $ -# endif - "GCFlags {statsFile = " - <> showbMaybePrecWith showbPrec 0 (statsFile gcfs) - <> ", giveStats = " - <> showb (FromStringShow $ giveStats gcfs) - <> ", maxStkSize = " - <> showb (maxStkSize gcfs) - <> ", initialStkSize = " - <> showb (initialStkSize gcfs) - <> ", stkChunkSize = " - <> showb (stkChunkSize gcfs) - <> ", stkChunkBufferSize = " - <> showb (stkChunkBufferSize gcfs) - <> ", maxHeapSize = " - <> showb (maxHeapSize gcfs) - <> ", minAllocAreaSize = " - <> showb (minAllocAreaSize gcfs) - <> ", minOldGenSize = " - <> showb (minOldGenSize gcfs) - <> ", heapSizeSuggestion = " - <> showb (heapSizeSuggestion gcfs) - <> ", heapSizeSuggestionAuto = " - <> showbBool (heapSizeSuggestionAuto gcfs) - <> ", oldGenFactor = " - <> showbDoublePrec 0 (oldGenFactor gcfs) - <> ", pcFreeHeap = " - <> showbDoublePrec 0 (pcFreeHeap gcfs) - <> ", generations = " - <> showb (generations gcfs) - <> ", steps = " - <> showb (steps gcfs) - <> ", squeezeUpdFrames = " - <> showbBool (squeezeUpdFrames gcfs) - <> ", compact = " - <> showbBool (compact gcfs) - <> ", compactThreshold = " - <> showbDoublePrec 0 (compactThreshold gcfs) - <> ", sweep = " - <> showbBool (sweep gcfs) - <> ", ringBell = " - <> showbBool (ringBell gcfs) - <> ", frontpanel = " - <> showbBool (frontpanel gcfs) - <> ", idleGCDelayTime = " - <> showbWord64 (idleGCDelayTime gcfs) - <> ", doIdleGC = " - <> showbBool (doIdleGC gcfs) - <> ", heapBase = " - <> showbWord (heapBase gcfs) - <> ", allocLimitGrace = " - <> showbWord (allocLimitGrace gcfs) - <> singleton '}' - --- | Convert a 'ConcFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbConcFlagsPrec :: Int -> ConcFlags -> Builder -showbConcFlagsPrec = showbPrec -{-# INLINE showbConcFlagsPrec #-} - --- | Convert a 'MiscFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbMiscFlagsPrec :: Int -> MiscFlags -> Builder -showbMiscFlagsPrec = showbPrec -{-# INLINE showbMiscFlagsPrec #-} - --- | Convert a 'DebugFlags' value to a 'Builder' with the given precedence. --- --- /Since: 0.5/ -showbDebugFlagsPrec :: Int -> DebugFlags -> Builder -showbDebugFlagsPrec = showbPrec -{-# INLINE showbDebugFlagsPrec #-} - --- | Convert a 'CCFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbCCFlagsPrec :: Int -> CCFlags -> Builder -# if __GLASGOW_HASKELL__ >= 711 -showbCCFlagsPrec _ ccfs = -# else -showbCCFlagsPrec p ccfs = showbParen (p > appPrec) $ -# endif - "CCFlags {doCostCentres = " - <> showb (FromStringShow $ doCostCentres ccfs) - <> ", profilerTicks = " - <> showbIntPrec 0 (profilerTicks ccfs) - <> ", msecsPerTick = " - <> showbIntPrec 0 (msecsPerTick ccfs) - <> singleton '}' - --- | Convert a 'ProfFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbProfFlagsPrec :: Int -> ProfFlags -> Builder -# if __GLASGOW_HASKELL__ >= 711 -showbProfFlagsPrec _ pfs = -# else -showbProfFlagsPrec p pfs = showbParen (p > appPrec) $ -# endif - "ProfFlags {doHeapProfile = " - <> showb (FromStringShow $ doHeapProfile pfs) - <> ", heapProfileInterval = " - <> showbWord64 (heapProfileInterval pfs) - <> ", heapProfileIntervalTicks = " - <> showbWord (heapProfileIntervalTicks pfs) - <> ", includeTSOs = " - <> showbBool (includeTSOs pfs) - <> ", showCCSOnException = " - <> showbBool (showCCSOnException pfs) - <> ", maxRetainerSetSize = " - <> showbWord (maxRetainerSetSize pfs) - <> ", ccsLength = " - <> showbWord (ccsLength pfs) - <> ", modSelector = " - <> showbMaybePrecWith showbPrec 0 (modSelector pfs) - <> ", descrSelector = " - <> showbMaybePrecWith showbPrec 0 (descrSelector pfs) - <> ", typeSelector = " - <> showbMaybePrecWith showbPrec 0 (typeSelector pfs) - <> ", ccSelector = " - <> showbMaybePrecWith showbPrec 0 (ccSelector pfs) - <> ", ccsSelector = " - <> showbMaybePrecWith showbPrec 0 (ccsSelector pfs) - <> ", retainerSelector = " - <> showbMaybePrecWith showbPrec 0 (retainerSelector pfs) - <> ", bioSelector = " - <> showbMaybePrecWith showbPrec 0 (bioSelector pfs) - <> singleton '}' - --- | Convert a 'TraceFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbTraceFlagsPrec :: Int -> TraceFlags -> Builder -# if __GLASGOW_HASKELL__ >= 711 -showbTraceFlagsPrec _ tfs = -# else -showbTraceFlagsPrec p tfs = showbParen (p > appPrec) $ -# endif - "TraceFlags {tracing = " - <> showb (FromStringShow $ tracing tfs) - <> ", timestamp = " - <> showbBool (timestamp tfs) - <> ", traceScheduler = " - <> showbBool (traceScheduler tfs) - <> ", traceGc = " - <> showbBool (traceGc tfs) - <> ", sparksSampled = " - <> showbBool (sparksSampled tfs) - <> ", sparksFull = " - <> showbBool (sparksFull tfs) - <> ", user = " - <> showbBool (user tfs) - <> singleton '}' - --- | Convert a 'TickyFlags' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbTickyFlagsPrec :: Int -> TickyFlags -> Builder -showbTickyFlagsPrec = showbPrec -{-# INLINE showbTickyFlagsPrec #-} - -$(deriveShow ''RTSFlags) - -instance Show GCFlags where - showbPrec = showbGCFlagsPrec - {-# INLINE showbPrec #-} - -$(deriveShow ''ConcFlags) - -$(deriveShow ''MiscFlags) - -$(deriveShow ''DebugFlags) - -instance Show CCFlags where - showbPrec = showbCCFlagsPrec - {-# INLINE showbPrec #-} - -instance Show ProfFlags where - showbPrec = showbProfFlagsPrec - {-# INLINE showbPrec #-} - -instance Show TraceFlags where - showbPrec = showbTraceFlagsPrec - {-# INLINE showbPrec #-} - -$(deriveShow ''TickyFlags) -#endif
− src/Text/Show/Text/GHC/StaticPtr.hs
@@ -1,47 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,8,0) -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.StaticPtr -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'StaticPtrInfo' values. -This module only exports functions if using @base-4.8.0.0@ or later. - -/Since: 0.5/ --} -module Text.Show.Text.GHC.StaticPtr ( -#if !(MIN_VERSION_base(4,8,0)) - ) where -#else - showbStaticPtrInfoPrec - ) where - -import Data.Text.Lazy.Builder (Builder) - -import GHC.StaticPtr (StaticPtrInfo) - -import Text.Show.Text.Classes (showbPrec) -import Text.Show.Text.Data.Char () -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Data.List () -import Text.Show.Text.Data.Tuple () -import Text.Show.Text.TH.Internal (deriveShow) - --- | Conver a 'StaticPtrInfo' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.8.0.0@ or later. --- --- /Since: 0.5/ -showbStaticPtrInfoPrec :: Int -> StaticPtrInfo -> Builder -showbStaticPtrInfoPrec = showbPrec -{-# INLINE showbStaticPtrInfoPrec #-} - -$(deriveShow ''StaticPtrInfo) -#endif
− src/Text/Show/Text/GHC/Stats.hs
@@ -1,45 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,5,0) -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.Stats -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'GCStats'. -This module only exports functions if using @base-4.5.0.0@ or later. - -/Since: 0.3/ --} -module Text.Show.Text.GHC.Stats ( -#if !(MIN_VERSION_base(4,5,0)) - ) where -#else - showbGCStatsPrec - ) where - -import Data.Text.Lazy.Builder (Builder) - -import GHC.Stats (GCStats) - -import Text.Show.Text.Classes (showbPrec) -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Data.Floating () -import Text.Show.Text.TH.Internal (deriveShow) - --- | Convert a 'GCStats' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.5.0.0@ or later. --- --- /Since: 0.3/ -showbGCStatsPrec :: Int -> GCStats -> Builder -showbGCStatsPrec = showbPrec -{-# INLINE showbGCStatsPrec #-} - -$(deriveShow ''GCStats) -#endif
− src/Text/Show/Text/GHC/TypeLits.hs
@@ -1,125 +0,0 @@-{-# LANGUAGE CPP #-} - -#if MIN_VERSION_base(4,6,0) -# if !(MIN_VERSION_base(4,7,0)) -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE UndecidableInstances #-} -# endif - -{-# OPTIONS_GHC -fno-warn-orphans #-} -#endif -{-| -Module: Text.Show.Text.GHC.TypeLits -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for data types in the @GHC.TypeLits@ module. -This module only exports functions if using @base-4.6.0.0@ or later. - -/Since: 0.5/ --} -module Text.Show.Text.GHC.TypeLits ( -#if MIN_VERSION_base(4,7,0) - showbSomeNatPrec - , showbSomeSymbol - ) where -#elif MIN_VERSION_base(4,6,0) - showbIsEven - , showbIsZero - , showbSingPrec - ) where -#else - ) where -#endif - -#if MIN_VERSION_base(4,6,0) - -import Data.Text.Lazy.Builder (Builder) -import Prelude hiding (Show) -import Text.Show.Text.Classes (Show(showb, showbPrec)) - -# if MIN_VERSION_base(4,7,0) -import GHC.TypeLits (SomeNat(..), SomeSymbol(..), natVal, symbolVal) -import Text.Show.Text.Data.Char (showbString) -import Text.Show.Text.Data.Integral (showbIntegerPrec) -# else -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (singleton) -import GHC.TypeLits (IsEven(..), IsZero(..), Kind, Sing, SingE(fromSing)) -import Text.Show.Text.Data.Integral () -# endif - -# if MIN_VERSION_base(4,7,0) --- | Convert a 'SomeNat' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.7.0.0@ or later. --- --- /Since: 0.5/ -showbSomeNatPrec :: Int -> SomeNat -> Builder -showbSomeNatPrec p (SomeNat x) = showbIntegerPrec p $ natVal x -{-# INLINE showbSomeNatPrec #-} - --- | Convert a 'SomeSymbol' value to a 'Builder' with the given precedence. --- This function is only available with @base-4.7.0.0@ or later. --- --- /Since: 0.5/ -showbSomeSymbol :: SomeSymbol -> Builder -showbSomeSymbol (SomeSymbol x) = showbString $ symbolVal x -{-# INLINE showbSomeSymbol #-} -# else --- | Convert an 'IsEven' value to a 'Builder'. --- This function is only available with @base-4.6@. --- --- /Since: 0.5/ -showbIsEven :: IsEven n -> Builder -showbIsEven IsEvenZero = singleton '0' -showbIsEven (IsEven x) = "(2 * " <> showb x <> singleton ')' -showbIsEven (IsOdd x) = "(2 * " <> showb x <> " + 1)" -{-# INLINE showbIsEven #-} - --- | Convert an 'IsZero' value to a 'Builder'. --- This function is only available with @base-4.6@. --- --- /Since: 0.5/ -showbIsZero :: IsZero n -> Builder -showbIsZero IsZero = singleton '0' -showbIsZero (IsSucc n) = singleton '(' <> showb n <> " + 1)" -{-# INLINE showbIsZero #-} - --- | Convert a 'Sing' value to a 'Builder' with the given precedence. --- --- /Since: 0.8/ -showbSingPrec :: (SingE (Kind :: k) rep, Show rep) => Int -> Sing (a :: k) -> Builder -showbSingPrec p = showbPrec p . fromSing -{-# INLINE showbSingPrec #-} -# endif - -# if MIN_VERSION_base(4,7,0) -instance Show SomeNat where - showbPrec = showbSomeNatPrec - {-# INLINE showbPrec #-} - -instance Show SomeSymbol where - showb = showbSomeSymbol - {-# INLINE showb #-} -# else -instance Show (IsEven n) where - showb = showbIsEven - {-# INLINE showb #-} - -instance Show (IsZero n) where - showb = showbIsZero - {-# INLINE showb #-} - -instance (SingE (Kind :: k) rep, Show rep) => Show (Sing (a :: k)) where - showbPrec = showbSingPrec - {-# INLINE showbPrec #-} -# endif - -#endif
− src/Text/Show/Text/Generic.hs
@@ -1,446 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} - -#if __GLASGOW_HASKELL__ >= 702 -{-# LANGUAGE DeriveGeneric #-} -#else -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeSynonymInstances #-} -#endif - -#if __GLASGOW_HASKELL__ >= 706 -{-# LANGUAGE PolyKinds #-} -#endif - -#if __GLASGOW_HASKELL__ >= 708 -{-# LANGUAGE StandaloneDeriving #-} -#endif -{-| -Module: Text.Show.Text.Generic -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Generic versions of 'Show' and 'Show1' class functions, as an alternative to -"Text.Show.Text.TH", which uses Template Haskell. Because there is no 'Generic2' -class, 'T.Show2' cannot be implemented generically. - -This implementation is based off of the @Generics.Deriving.Show@ module from the -@generic-deriving@ library. - -/Since: 0.6/ --} -module Text.Show.Text.Generic ( - -- * Generic @show@ functions - -- $generics - - -- ** Understanding a compiler error - -- $generic_err - genericShow - , genericShowLazy - , genericShowPrec - , genericShowPrecLazy - , genericShowList - , genericShowListLazy - , genericShowb - , genericShowbPrec - , genericShowbList - , genericPrint - , genericPrintLazy - , genericHPrint - , genericHPrintLazy - , genericShowbPrecWith - , genericShowbPrec1 - -- * The 'GShow' and 'GShow1' classes - , GShow(..) - , GShow1(..) - , ConType(..) - ) where - -import Data.Monoid.Compat ((<>)) -import qualified Data.Text as TS (Text) -import qualified Data.Text.IO as TS (putStrLn, hPutStrLn) -import Data.Text.Lazy (toStrict) -import Data.Text.Lazy.Builder (Builder, fromString, singleton, toLazyText) -import qualified Data.Text.Lazy as TL (Text) -import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn) -import Data.Typeable (Typeable) - -import Generics.Deriving.Base -#if __GLASGOW_HASKELL__ < 702 -import qualified Generics.Deriving.TH as Generics (deriveAll) -#endif -import GHC.Show (appPrec, appPrec1) - -import Prelude () -import Prelude.Compat hiding (Show) - -import System.IO (Handle) - -import qualified Text.Show as S (Show) -import qualified Text.Show.Text.Classes as T -import Text.Show.Text.Classes (Show(showbPrec), Show1(..), - showbListWith, showbParen, showbSpace) -import Text.Show.Text.Instances () -import Text.Show.Text.Utils (isInfixTypeCon, isTupleString) - -#include "inline.h" - -{- $generics - -'T.Show' instances can be easily defined for data types that are 'Generic' instances. -The easiest way to do this is to use the @DeriveGeneric@ extension. - -@ -{-# LANGUAGE DeriveGeneric #-} -import GHC.Generics -import Text.Show.Text -import Text.Show.Generic - -data D a = D a - deriving (Generic, Generic1) - -instance Show a => Show (D a) where - showbPrec = 'genericShowbPrec' - -instance Show1 D where - showbPrecWith = 'genericShowbPrecWith' -@ --} - -{- $generic_err - -Suppose you intend to use 'genericShowbPrec' to define a 'T.Show' instance. - -@ -data Oops1 = Oops1 - -- forgot to add \"deriving Generic\" here! - -instance Show Oops1 where - showbPrec = 'genericShowbPrec' -@ - -If you forget to add a @deriving 'Generic'@ clause to your data type, at -compile-time, you will get an error message that begins roughly as follows: - -@ -No instance for ('GShow' (Rep Oops1)) -@ - -This error can be confusing, but don't let it intimidate you. The correct fix is -simply to add the missing \"@deriving 'Generic'@\" clause. - -Similarly, if the compiler complains about not having an instance for @('GShow1' -(Rep1 Oops2))@, add a \"@deriving 'Generic1'@\" clause. --} - --- | A 'Generic' implementation of 'T.show'. --- --- /Since: 0.6/ -genericShow :: (Generic a, GShow (Rep a)) => a -> TS.Text -genericShow = toStrict . genericShowLazy - --- | A 'Generic' implementation of 'T.showLazy'. --- --- /Since: 0.6/ -genericShowLazy :: (Generic a, GShow (Rep a)) => a -> TL.Text -genericShowLazy = toLazyText . genericShowb - --- | A 'Generic' implementation of 'T.showPrec'. --- --- /Since: 0.6/ -genericShowPrec :: (Generic a, GShow (Rep a)) => Int -> a -> TS.Text -genericShowPrec p = toStrict . genericShowPrecLazy p - --- | A 'Generic' implementation of 'T.showPrecLazy'. --- --- /Since: 0.6/ -genericShowPrecLazy :: (Generic a, GShow (Rep a)) => Int -> a -> TL.Text -genericShowPrecLazy p = toLazyText . genericShowbPrec p - --- | A 'Generic' implementation of 'T.showList'. --- --- /Since: 0.6/ -genericShowList :: (Generic a, GShow (Rep a)) => [a] -> TS.Text -genericShowList = toStrict . genericShowListLazy - --- | A 'Generic' implementation of 'T.showListLazy'. --- --- /Since: 0.6/ -genericShowListLazy :: (Generic a, GShow (Rep a)) => [a] -> TL.Text -genericShowListLazy = toLazyText . genericShowbList - --- | A 'Generic' implementation of 'T.showb'. --- --- /Since: 0.6/ -genericShowb :: (Generic a, GShow (Rep a)) => a -> Builder -genericShowb = genericShowbPrec 0 - --- | A 'Generic' implementation of 'T.showbPrec'. --- --- /Since: 0.6/ -genericShowbPrec :: (Generic a, GShow (Rep a)) => Int -> a -> Builder -genericShowbPrec p = gShowbPrec Pref p . from - --- | A 'Generic' implementation of 'T.showbList'. --- --- /Since: 0.6/ -genericShowbList :: (Generic a, GShow (Rep a)) => [a] -> Builder -genericShowbList = showbListWith genericShowb - --- | A 'Generic' implementation of 'T.print'. --- --- /Since: 0.6/ -genericPrint :: (Generic a, GShow (Rep a)) => a -> IO () -genericPrint = TS.putStrLn . genericShow - --- | A 'Generic' implementation of 'T.printLazy'. --- --- /Since: 0.6/ -genericPrintLazy :: (Generic a, GShow (Rep a)) => a -> IO () -genericPrintLazy = TL.putStrLn . genericShowLazy - --- | A 'Generic' implementation of 'T.hPrint'. --- --- /Since: 0.6/ -genericHPrint :: (Generic a, GShow (Rep a)) => Handle -> a -> IO () -genericHPrint h = TS.hPutStrLn h . genericShow - --- | A 'Generic' implementation of 'T.hPrintLazy'. --- --- /Since: 0.6/ -genericHPrintLazy :: (Generic a, GShow (Rep a)) => Handle -> a -> IO () -genericHPrintLazy h = TL.hPutStrLn h . genericShowLazy - --- | A 'Generic1' implementation of 'showbPrecWith'. --- --- /Since: 1/ -genericShowbPrecWith :: (Generic1 f, GShow1 (Rep1 f)) - => (Int -> a -> Builder) -> Int -> f a -> Builder -genericShowbPrecWith sp p = gShowbPrecWith Pref sp p . from1 - --- | A 'Generic'/'Generic1' implementation of 'showbPrec1'. --- --- /Since: 1/ -genericShowbPrec1 :: (Generic a, Generic1 f, GShow (Rep a), GShow1 (Rep1 f)) - => Int -> f a -> Builder -genericShowbPrec1 = genericShowbPrecWith genericShowbPrec - -------------------------------------------------------------------------------- - --- | Whether a constructor is a record ('Rec'), a tuple ('Tup'), is prefix ('Pref'), --- or infix ('Inf'). --- --- /Since: 0.6/ -data ConType = Rec | Tup | Pref | Inf String - deriving ( Eq - , Ord - , Read - , S.Show - , Typeable -#if __GLASGOW_HASKELL__ >= 702 - , Generic -#endif - ) - -instance T.Show ConType where - showbPrec = genericShowbPrec - INLINE_INST_FUN(showbPrec) - --- | Class of generic representation types ('Rep') that can be converted to --- a 'Builder'. --- --- /Since: 0.6/ -class GShow f where - -- | This is used as the default generic implementation of 'showbPrec'. - gShowbPrec :: ConType -> Int -> f a -> Builder - -- | Whether a representation type has any constructors. - isNullary :: f a -> Bool - isNullary = error "generic showbPrec (isNullary): unnecessary case" -#if __GLASGOW_HASKELL__ >= 708 - {-# MINIMAL gShowbPrec #-} - -deriving instance Typeable GShow -#endif - -instance GShow U1 where - gShowbPrec _ _ U1 = mempty - isNullary _ = True - -instance T.Show c => GShow (K1 i c) where - gShowbPrec _ n (K1 a) = showbPrec n a - isNullary _ = False - -instance (Constructor c, GShow f) => GShow (C1 c f) where - gShowbPrec = gShowbConstructor gShowbPrec isNullary - -instance (Selector s, GShow f) => GShow (S1 s f) where - gShowbPrec = gShowbSelector gShowbPrec - isNullary (M1 x) = isNullary x - -instance GShow f => GShow (D1 d f) where - gShowbPrec t n (M1 x) = gShowbPrec t n x - -instance (GShow f, GShow g) => GShow (f :+: g) where - gShowbPrec t n (L1 x) = gShowbPrec t n x - gShowbPrec t n (R1 x) = gShowbPrec t n x - -instance (GShow f, GShow g) => GShow (f :*: g) where - gShowbPrec = gShowbProduct gShowbPrec gShowbPrec - -- If we have a product then it is not a nullary constructor - isNullary _ = False - -------------------------------------------------------------------------------- - --- | Class of generic representation types ('Rep1') that can be converted to --- a 'Builder' by lifting through a unary type constructor. --- --- /Since: 1/ -class GShow1 f where - -- | This is used as the default generic implementation of 'showbPrecWith'. - gShowbPrecWith :: ConType -> (Int -> a -> Builder) -> Int -> f a -> Builder - -- | Whether a representation type has any constructors. - isNullary1 :: f a -> Bool - isNullary1 = error "generic showbPrecWith (isNullary1): unnecessary case" -#if __GLASGOW_HASKELL__ >= 708 - {-# MINIMAL gShowbPrecWith #-} - -deriving instance Typeable GShow1 -#endif - -instance GShow1 U1 where - gShowbPrecWith _ _ _ U1 = mempty - isNullary1 _ = True - -instance GShow1 Par1 where - gShowbPrecWith _ sp n (Par1 p) = sp n p - isNullary1 _ = False - -instance T.Show c => GShow1 (K1 i c) where - gShowbPrecWith _ _ n (K1 a) = showbPrec n a - isNullary1 _ = False - -instance Show1 f => GShow1 (Rec1 f) where - gShowbPrecWith _ sp n (Rec1 r) = showbPrecWith sp n r - isNullary1 _ = False - -instance (Constructor c, GShow1 f) => GShow1 (C1 c f) where - gShowbPrecWith t sp = gShowbConstructor (flip gShowbPrecWith sp) isNullary1 t - -instance (Selector s, GShow1 f) => GShow1 (S1 s f) where - gShowbPrecWith t sp = gShowbSelector (flip gShowbPrecWith sp) t - isNullary1 (M1 x) = isNullary1 x - -instance GShow1 f => GShow1 (D1 d f) where - gShowbPrecWith t sp n (M1 x) = gShowbPrecWith t sp n x - -instance (GShow1 f, GShow1 g) => GShow1 (f :+: g) where - gShowbPrecWith t sp n (L1 x) = gShowbPrecWith t sp n x - gShowbPrecWith t sp n (R1 x) = gShowbPrecWith t sp n x - -instance (GShow1 f, GShow1 g) => GShow1 (f :*: g) where - gShowbPrecWith t sp = gShowbProduct (flip gShowbPrecWith sp) (flip gShowbPrecWith sp) t - -- If we have a product then it is not a nullary constructor - isNullary1 _ = False - -instance (Show1 f, GShow1 g) => GShow1 (f :.: g) where - gShowbPrecWith t sp n (Comp1 c) = showbPrecWith (gShowbPrecWith t sp) n c - isNullary1 _ = False - -------------------------------------------------------------------------------- --- Shared code between GShow and GShow1 -------------------------------------------------------------------------------- - -gShowbConstructor :: forall c f p. Constructor c - => (ConType -> Int -> f p -> Builder) - -> (f p -> Bool) - -> ConType -> Int -> C1 c f p -> Builder -gShowbConstructor gs isNull _ n c@(M1 x) = case fixity of - Prefix -> showbParen ( n > appPrec - && not ( isNull x - || conIsTuple c -#if __GLASGOW_HASKELL__ >= 711 - || conIsRecord c -#endif - ) - ) $ - (if conIsTuple c - then mempty - else let cn = conName c - in showbParen (isInfixTypeCon cn) $ fromString cn - ) - <> (if isNull x || conIsTuple c - then mempty - else singleton ' ' - ) - <> showbBraces t (gs t appPrec1 x) - Infix _ m -> showbParen (n > m) . showbBraces t $ gs t (m+1) x - where - fixity :: Fixity - fixity = conFixity c - - t :: ConType - t = if conIsRecord c - then Rec - else case conIsTuple c of - True -> Tup - False -> case fixity of - Prefix -> Pref - Infix _ _ -> Inf $ conName c - - showbBraces :: ConType -> Builder -> Builder - showbBraces Rec b = singleton '{' <> b <> singleton '}' - showbBraces Tup b = singleton '(' <> b <> singleton ')' - showbBraces Pref b = b - showbBraces (Inf _) b = b - - conIsTuple :: C1 c f p -> Bool - conIsTuple = isTupleString . conName - -gShowbSelector :: Selector s - => (ConType -> Int -> f p -> Builder) - -> ConType -> Int -> S1 s f p -> Builder -gShowbSelector gs t n sel@(M1 x) - | selName sel == "" = gs t n x - | otherwise = fromString (selName sel) <> " = " <> gs t 0 x - -gShowbProduct :: (ConType -> Int -> f p -> Builder) - -> (ConType -> Int -> g p -> Builder) - -> ConType -> Int -> ((f :*: g) p) -> Builder -gShowbProduct gsa gsb t@Rec _ (a :*: b) = - gsa t 0 a - <> ", " - <> gsb t 0 b -gShowbProduct gsa gsb t@(Inf o) n (a :*: b) = - gsa t n a - <> showbSpace - <> infixOp - <> showbSpace - <> gsb t n b - where - infixOp :: Builder - infixOp = if isInfixTypeCon o - then fromString o - else singleton '`' <> fromString o <> singleton '`' -gShowbProduct gsa gsb t@Tup _ (a :*: b) = - gsa t 0 a - <> singleton ',' - <> gsb t 0 b -gShowbProduct gsa gsb t@Pref n (a :*: b) = - gsa t n a - <> showbSpace - <> gsb t n b - -------------------------------------------------------------------------------- - -#if __GLASGOW_HASKELL__ < 702 -$(Generics.deriveAll ''ConType) -#endif
− src/Text/Show/Text/Instances.hs
@@ -1,65 +0,0 @@-{-| -Module: Text.Show.Text.Instances -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Imports all orphan 'Show', 'Show1', and 'Show2' instances covered by @text-show@ -(except for the instances in `Text.Show.Text.Functions`, which are not imported -by default). --} -module Text.Show.Text.Instances () where - -import Text.Show.Text.Control.Applicative () -import Text.Show.Text.Control.Concurrent () -import Text.Show.Text.Control.Exception () -import Text.Show.Text.Control.Monad.ST () - -import Text.Show.Text.Data.Array () -import Text.Show.Text.Data.Bool () -import Text.Show.Text.Data.ByteString () -import Text.Show.Text.Data.Char () -import Text.Show.Text.Data.Complex () -import Text.Show.Text.Data.Data () -import Text.Show.Text.Data.Dynamic () -import Text.Show.Text.Data.Either () -import Text.Show.Text.Data.Fixed () -import Text.Show.Text.Data.Floating () -import Text.Show.Text.Data.Functor.Identity () -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Data.List () -import Text.Show.Text.Data.Maybe () -import Text.Show.Text.Data.Monoid () -import Text.Show.Text.Data.OldTypeable () -import Text.Show.Text.Data.Ord () -import Text.Show.Text.Data.Proxy () -import Text.Show.Text.Data.Ratio () -import Text.Show.Text.Data.Text () -import Text.Show.Text.Data.Tuple () -import Text.Show.Text.Data.Type.Coercion () -import Text.Show.Text.Data.Type.Equality () -import Text.Show.Text.Data.Typeable () -import Text.Show.Text.Data.Version () -import Text.Show.Text.Data.Void () - -import Text.Show.Text.Foreign.C.Types () -import Text.Show.Text.Foreign.Ptr () - -import Text.Show.Text.GHC.Conc.Windows () -import Text.Show.Text.GHC.Event () -import Text.Show.Text.GHC.Fingerprint () -import Text.Show.Text.GHC.Generics () -import Text.Show.Text.GHC.RTS.Flags () -import Text.Show.Text.GHC.StaticPtr () -import Text.Show.Text.GHC.Stats () -import Text.Show.Text.GHC.TypeLits () - -import Text.Show.Text.Numeric.Natural () - -import Text.Show.Text.System.Exit () -import Text.Show.Text.System.IO () -import Text.Show.Text.System.Posix.Types () - -import Text.Show.Text.Text.Read ()
− src/Text/Show/Text/Numeric/Natural.hs
@@ -1,53 +0,0 @@-{-# LANGUAGE CPP #-} -#if MIN_VERSION_base(4,8,0) -{-# LANGUAGE MagicHash #-} -#endif -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Numeric.Natural -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Natural's. - -/Since: 0.5/ --} -module Text.Show.Text.Numeric.Natural (showbNaturalPrec) where - -import Data.Text.Lazy.Builder (Builder) - -#if MIN_VERSION_base(4,8,0) -import GHC.Integer.GMP.Internals (Integer(..)) -import GHC.Natural (Natural(..)) -import GHC.Types (Word(..)) - -import Text.Show.Text.Data.Integral (showbWord) -#else -import Numeric.Natural (Natural) -#endif - -import Prelude hiding (Show) - -import Text.Show.Text.Classes (Show(showbPrec)) -import Text.Show.Text.Data.Integral (showbIntegerPrec) - -#include "inline.h" - --- | Convert a 'Natural' to a 'Builder' with the given precedence. --- --- /Since: 0.5/ -showbNaturalPrec :: Int -> Natural -> Builder -#if MIN_VERSION_base(4,8,0) -showbNaturalPrec _ (NatS# w#) = showbWord $ W# w# -showbNaturalPrec p (NatJ# bn) = showbIntegerPrec p $ Jp# bn -#else -showbNaturalPrec p = showbIntegerPrec p . toInteger -{-# INLINE showbNaturalPrec #-} -#endif - -instance Show Natural where - showbPrec = showbNaturalPrec - INLINE_INST_FUN(showbPrec)
− src/Text/Show/Text/System/Exit.hs
@@ -1,32 +0,0 @@-{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.System.Exit -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'ExitCode'. - -/Since: 0.3/ --} -module Text.Show.Text.System.Exit (showbExitCodePrec) where - -import Data.Text.Lazy.Builder (Builder) - -import System.Exit (ExitCode) - -import Text.Show.Text.Classes (showbPrec) -import Text.Show.Text.Data.Integral () -import Text.Show.Text.TH.Internal (deriveShow) - --- | Convert an 'ExitCode' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbExitCodePrec :: Int -> ExitCode -> Builder -showbExitCodePrec = showbPrec -{-# INLINE showbExitCodePrec #-} - -$(deriveShow ''ExitCode)
− src/Text/Show/Text/System/IO.hs
@@ -1,158 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.System.IO -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'IO'-related data types. - -/Since: 0.3/ --} -module Text.Show.Text.System.IO ( - showbHandle - , showbIOMode - , showbBufferModePrec - , showbHandlePosn - , showbSeekMode - , showbTextEncoding -#if MIN_VERSION_base(4,4,0) - , showbCodingProgress - , showbCodingFailureMode -#endif - , showbNewline - , showbNewlineModePrec - ) where - -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy.Builder (Builder, fromString, singleton) - -import GHC.IO.Encoding.Types (TextEncoding(textEncodingName)) -#if MIN_VERSION_base(4,4,0) -import GHC.IO.Encoding.Failure (CodingFailureMode) -import GHC.IO.Encoding.Types (CodingProgress) -#endif -import GHC.IO.Handle (HandlePosn(..)) -import GHC.IO.Handle.Types (Handle(..)) - -import Prelude hiding (Show) - -import System.IO (BufferMode, IOMode, Newline, NewlineMode, SeekMode) - -import Text.Show.Text.Classes (Show(showb, showbPrec)) -import Text.Show.Text.Data.Integral (showbIntegerPrec) -import Text.Show.Text.Data.Maybe () -import Text.Show.Text.TH.Internal (deriveShow) - -#include "inline.h" - --- | Convert a 'Handle' to a 'Builder'. --- --- /Since: 0.3/ -showbHandle :: Handle -> Builder -showbHandle (FileHandle file _) = showbHandleFilePath file -showbHandle (DuplexHandle file _ _) = showbHandleFilePath file -{-# INLINE showbHandle #-} - --- | Convert a 'Handle`'s 'FilePath' to a 'Builder'. -showbHandleFilePath :: FilePath -> Builder -showbHandleFilePath file = "{handle: " <> fromString file <> singleton '}' -{-# INLINE showbHandleFilePath #-} - --- | Convert an 'IOMode' to a 'Builder'. --- --- /Since: 0.3/ -showbIOMode :: IOMode -> Builder -showbIOMode = showb -{-# INLINE showbIOMode #-} - --- | Convert a 'BufferMode' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbBufferModePrec :: Int -> BufferMode -> Builder -showbBufferModePrec = showbPrec -{-# INLINE showbBufferModePrec #-} - --- | Convert a 'HandlePosn' to a 'Builder'. --- --- /Since: 0.3/ -showbHandlePosn :: HandlePosn -> Builder -showbHandlePosn (HandlePosn h pos) - = showbHandle h <> " at position " <> showbIntegerPrec 0 pos -{-# INLINE showbHandlePosn #-} - --- | Convert a 'SeekMode' to a 'Builder'. --- --- /Since: 0.3/ -showbSeekMode :: SeekMode -> Builder -showbSeekMode = showb -{-# INLINE showbSeekMode #-} - --- | Convert a 'TextEncoding' to a 'Builder'. --- --- /Since: 0.3/ -showbTextEncoding :: TextEncoding -> Builder -showbTextEncoding = fromString . textEncodingName -{-# INLINE showbTextEncoding #-} - -#if MIN_VERSION_base(4,4,0) --- | Convert a 'CodingProgress' to a 'Builder'. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 0.3/ -showbCodingProgress :: CodingProgress -> Builder -showbCodingProgress = showb -{-# INLINE showbCodingProgress #-} - --- | Convert a 'CodingFailureMode' value to a 'Builder'. --- This function is only available with @base-4.4.0.0@ or later. --- --- /Since: 0.3/ -showbCodingFailureMode :: CodingFailureMode -> Builder -showbCodingFailureMode = showb -{-# INLINE showbCodingFailureMode #-} -#endif - --- | Convert a 'Newline' to a 'Builder'. --- --- /Since: 0.3/ -showbNewline :: Newline -> Builder -showbNewline = showb -{-# INLINE showbNewline #-} - --- | Convert a 'NewlineMode' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbNewlineModePrec :: Int -> NewlineMode -> Builder -showbNewlineModePrec = showbPrec -{-# INLINE showbNewlineModePrec #-} - -instance Show Handle where - showb = showbHandle - INLINE_INST_FUN(showb) - -$(deriveShow ''IOMode) -$(deriveShow ''BufferMode) - -instance Show HandlePosn where - showb = showbHandlePosn - INLINE_INST_FUN(showb) - -$(deriveShow ''SeekMode) - -instance Show TextEncoding where - showb = showbTextEncoding - INLINE_INST_FUN(showb) - -#if MIN_VERSION_base(4,4,0) -$(deriveShow ''CodingProgress) -$(deriveShow ''CodingFailureMode) -#endif - -$(deriveShow ''Newline) -$(deriveShow ''NewlineMode)
− src/Text/Show/Text/System/Posix/Types.hs
@@ -1,394 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - -{-| -Module: Text.Show.Text.System.Posix.Types -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' functions for Haskell equivalents of POSIX data types. -Note that these functions are only available if the operating system supports them, -so some OSes (e.g., Windows) will not be able to use all of the functions in this -module. - -/Since: 0.3/ --} -#include "HsBaseConfig.h" - -module Text.Show.Text.System.Posix.Types ( - showbFdPrec -#if defined(HTYPE_DEV_T) - , showbCDev -#endif -#if defined(HTYPE_INO_T) - , showbCIno -#endif -#if defined(HTYPE_MODE_T) - , showbCMode -#endif -#if defined(HTYPE_OFF_T) - , showbCOffPrec -#endif -#if defined(HTYPE_PID_T) - , showbCPidPrec -#endif -#if defined(HTYPE_SSIZE_T) - , showbCSsizePrec -#endif -#if defined(HTYPE_GID_T) - , showbCGid -#endif -#if defined(HTYPE_NLINK_T) - , showbCNlink -#endif -#if defined(HTYPE_UID_T) - , showbCUid -#endif -#if defined(HTYPE_CC_T) - , showbCCc -#endif -#if defined(HTYPE_SPEED_T) - , showbCSpeed -#endif -#if defined(HTYPE_TCFLAG_T) - , showbCTcflag -#endif -#if defined(HTYPE_RLIM_T) - , showbCRLim -#endif - ) where - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import System.Posix.Types - -import Text.Show.Text.Classes (Show(showb, showbPrec)) -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Foreign.C.Types () - -#if !(MIN_VERSION_base(4,5,0)) -import Data.Int -import Data.Word - -import Unsafe.Coerce (unsafeCoerce) - -# include "HsBaseConfig.h" -# include "inline.h" -#endif - -#if defined(HTYPE_DEV_T) --- | Convert a 'CDev' to a 'Builder'. --- --- /Since: 0.3/ -showbCDev :: CDev -> Builder -# if MIN_VERSION_base(4,5,0) -showbCDev = showb -{-# INLINE showbCDev #-} -# else -showbCDev = unsafeCoerce (showb :: HTYPE_DEV_T -> Builder) -# endif -#endif - -#if defined(HTYPE_INO_T) --- | Convert a 'CIno' to a 'Builder'. --- --- /Since: 0.3/ -showbCIno :: CIno -> Builder -# if MIN_VERSION_base(4,5,0) -showbCIno = showb -{-# INLINE showbCIno #-} -# else -showbCIno = unsafeCoerce (showb :: HTYPE_INO_T -> Builder) -# endif -#endif - -#if defined(HTYPE_MODE_T) --- | Convert a 'CMode' to a 'Builder'. --- --- /Since: 0.3/ -showbCMode :: CMode -> Builder -# if MIN_VERSION_base(4,5,0) -showbCMode = showb -{-# INLINE showbCMode #-} -# else -showbCMode = unsafeCoerce (showb :: HTYPE_MODE_T -> Builder) -# endif -#endif - -#if defined(HTYPE_OFF_T) --- | Convert a 'COff' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCOffPrec :: Int -> COff -> Builder -# if MIN_VERSION_base(4,5,0) -showbCOffPrec = showbPrec -{-# INLINE showbCOffPrec #-} -# else -showbCOffPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_OFF_T -> Builder) -# endif -#endif - -#if defined(HTYPE_PID_T) --- | Convert a 'CPid' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCPidPrec :: Int -> CPid -> Builder -# if MIN_VERSION_base(4,5,0) -showbCPidPrec = showbPrec -{-# INLINE showbCPidPrec #-} -# else -showbCPidPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_PID_T -> Builder) -# endif -#endif - -#if defined(HTYPE_SSIZE_T) --- | Convert a 'CSsize' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbCSsizePrec :: Int -> CSsize -> Builder -# if MIN_VERSION_base(4,5,0) -showbCSsizePrec = showbPrec -{-# INLINE showbCSsizePrec #-} -# else -showbCSsizePrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SSIZE_T -> Builder) -# endif -#endif - -#if defined(HTYPE_GID_T) --- | Convert a 'CGid' to a 'Builder'. --- --- /Since: 0.3/ -showbCGid :: CGid -> Builder -# if MIN_VERSION_base(4,5,0) -showbCGid = showb -{-# INLINE showbCGid #-} -# else -showbCGid = unsafeCoerce (showb :: HTYPE_GID_T -> Builder) -# endif -#endif - -#if defined(HTYPE_NLINK_T) --- | Convert a 'CNlink' to a 'Builder'. --- --- /Since: 0.3/ -showbCNlink :: CNlink -> Builder -# if MIN_VERSION_base(4,5,0) -showbCNlink = showb -{-# INLINE showbCNlink #-} -# else -showbCNlink = unsafeCoerce (showb :: HTYPE_NLINK_T -> Builder) -# endif -#endif - -#if defined(HTYPE_UID_T) --- | Convert a 'CUid' to a 'Builder'. --- --- /Since: 0.3/ -showbCUid :: CUid -> Builder -# if MIN_VERSION_base(4,5,0) -showbCUid = showb -{-# INLINE showbCUid #-} -# else -showbCUid = unsafeCoerce (showb :: HTYPE_UID_T -> Builder) -# endif -#endif - -#if defined(HTYPE_CC_T) --- | Convert a 'CCc' to a 'Builder'. --- --- /Since: 0.3/ -showbCCc :: CCc -> Builder -# if MIN_VERSION_base(4,5,0) -showbCCc = showb -{-# INLINE showbCCc #-} -# else -showbCCc = unsafeCoerce (showb :: HTYPE_CC_T -> Builder) -# endif -#endif - -#if defined(HTYPE_SPEED_T) --- | Convert a 'CSpeed' to a 'Builder'. --- --- /Since: 0.3/ -showbCSpeed :: CSpeed -> Builder -# if MIN_VERSION_base(4,5,0) -showbCSpeed = showb -{-# INLINE showbCSpeed #-} -# else -showbCSpeed = unsafeCoerce (showb :: HTYPE_SPEED_T -> Builder) -# endif -#endif - -#if defined(HTYPE_TCFLAG_T) --- | Convert a 'CTcflag' to a 'Builder'. --- --- /Since: 0.3/ -showbCTcflag :: CTcflag -> Builder -# if MIN_VERSION_base(4,5,0) -showbCTcflag = showb -{-# INLINE showbCTcflag #-} -# else -showbCTcflag = unsafeCoerce (showb :: HTYPE_TCFLAG_T -> Builder) -# endif -#endif - -#if defined(HTYPE_RLIM_T) --- | Convert a 'CRLim' to a 'Builder'. --- --- /Since: 0.3/ -showbCRLim :: CRLim -> Builder -# if MIN_VERSION_base(4,5,0) -showbCRLim = showb -{-# INLINE showbCRLim #-} -# else -showbCRLim = unsafeCoerce (showb :: HTYPE_RLIM_T -> Builder) -# endif -#endif - --- | Convert an 'Fd' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbFdPrec :: Int -> Fd -> Builder -showbFdPrec = showbPrec -{-# INLINE showbFdPrec #-} - -#if MIN_VERSION_base(4,5,0) -# if defined(HTYPE_DEV_T) -deriving instance Show CDev -# endif - -# if defined(HTYPE_INO_T) -deriving instance Show CIno -# endif - -# if defined(HTYPE_MODE_T) -deriving instance Show CMode -# endif - -# if defined(HTYPE_OFF_T) -deriving instance Show COff -# endif - -# if defined(HTYPE_PID_T) -deriving instance Show CPid -# endif - -# if defined(HTYPE_SSIZE_T) -deriving instance Show CSsize -# endif - -# if defined(HTYPE_GID_T) -deriving instance Show CGid -# endif - -# if defined(HTYPE_NLINK_T) -deriving instance Show CNlink -# endif - -# if defined(HTYPE_UID_T) -deriving instance Show CUid -# endif - -# if defined(HTYPE_CC_T) -deriving instance Show CCc -# endif - -# if defined(HTYPE_SPEED_T) -deriving instance Show CSpeed -# endif - -# if defined(HTYPE_TCFLAG_T) -deriving instance Show CTcflag -# endif - -# if defined(HTYPE_RLIM_T) -deriving instance Show CRLim -# endif -#else -# if defined(HTYPE_DEV_T) -instance Show CDev where - showb = showbCDev - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_INO_T) -instance Show CIno where - showb = showbCIno - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_MODE_T) -instance Show CMode where - showb = showbCMode - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_OFF_T) -instance Show COff where - showbPrec = showbCOffPrec - INLINE_INST_FUN(showbPrec) -# endif - -# if defined(HTYPE_PID_T) -instance Show CPid where - showbPrec = showbCPidPrec - INLINE_INST_FUN(showbPrec) -# endif - -# if defined(HTYPE_SSIZE_T) -instance Show CSsize where - showbPrec = showbCSsizePrec - INLINE_INST_FUN(showbPrec) -# endif - -# if defined(HTYPE_GID_T) -instance Show CGid where - showb = showbCGid - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_NLINK_T) -instance Show CNlink where - showb = showbCNlink - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_UID_T) -instance Show CUid where - showb = showbCUid - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_CC_T) -instance Show CCc where - showb = showbCCc - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_SPEED_T) -instance Show CSpeed where - showb = showbCSpeed - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_TCFLAG_T) -instance Show CTcflag where - showb = showbCTcflag - INLINE_INST_FUN(showb) -# endif - -# if defined(HTYPE_RLIM_T) -instance Show CRLim where - showb = showbCRLim - INLINE_INST_FUN(showb) -# endif -#endif - -deriving instance Show Fd
− src/Text/Show/Text/TH.hs
@@ -1,18 +0,0 @@-{-| -Module: Text.Show.Text.TH -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Functions to mechanically derive 'T.Show', 'Show1', or 'Show2' instances, or to -splice @show@-related expressions into Haskell source code. You need to enable -the @TemplateHaskell@ language extension in order to use this module. - -/Since: 0.3/ --} -module Text.Show.Text.TH (module Text.Show.Text.TH.Internal) where - -import Text.Show.Text.Instances () -import Text.Show.Text.TH.Internal
− src/Text/Show/Text/TH/Internal.hs
@@ -1,1434 +0,0 @@-{-# LANGUAGE BangPatterns #-} -{-# LANGUAGE CPP #-} -{-# LANGUAGE MagicHash #-} -{-# LANGUAGE TemplateHaskell #-} -{-| -Module: Text.Show.Text.TH.Internal -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Functions to mechanically derive 'T.Show', 'Show1', or 'Show2' instances, or to -splice @show@-related expressions into Haskell source code. You need to enable -the @TemplateHaskell@ language extension in order to use this module. - -This implementation is loosely based off of the @Data.Aeson.TH@ module from the -@aeson@ library. --} -module Text.Show.Text.TH.Internal ( - -- * 'deriveShow' - -- $deriveShow - deriveShow - -- * 'deriveShow1' - -- $deriveShow1 - , deriveShow1 - -- * 'deriveShow2' - -- $deriveShow2 - , deriveShow2 - -- * @mk@ functions - -- $mk - , mkShow - , mkShowLazy - , mkShowPrec - , mkShowPrecLazy - , mkShowList - , mkShowListLazy - , mkShowb - , mkShowbPrec - , mkShowbList - , mkPrint - , mkPrintLazy - , mkHPrint - , mkHPrintLazy - , mkShowbPrecWith - , mkShowbPrec1 - , mkShowbPrecWith2 - , mkShowbPrec2 - ) where - -import Data.Function (on) -import Data.List.Compat (foldl', intersperse) -#if MIN_VERSION_template_haskell(2,7,0) -import Data.List.Compat (find) -#endif -import qualified Data.List.NonEmpty as NE -import Data.List.NonEmpty (NonEmpty(..), (<|)) -import qualified Data.Map as Map (fromList, lookup) -import Data.Map (Map) -import Data.Maybe (fromMaybe) -import Data.Monoid.Compat ((<>)) -import qualified Data.Set as Set -import Data.Set (Set) -import qualified Data.Text as TS () -import qualified Data.Text.IO as TS (putStrLn, hPutStrLn) -import Data.Text.Lazy (toStrict) -import Data.Text.Lazy.Builder (Builder, fromString, singleton, toLazyText) -import qualified Data.Text.Lazy as TL () -import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn) - -import GHC.Exts (Char(..), Double(..), Float(..), Int(..), Word(..)) -import GHC.Prim (Char#, Double#, Float#, Int#, Word#) -import GHC.Show (appPrec, appPrec1) - -import Language.Haskell.TH.Lib -import Language.Haskell.TH.Ppr hiding (appPrec) -import Language.Haskell.TH.Syntax - -import Prelude () -import Prelude.Compat hiding (Show) - -import qualified Text.Show as S (Show(show)) -import qualified Text.Show.Text.Classes as T -import Text.Show.Text.Classes (Show1(..), Show2(..), showbPrec, - showbListWith, showbParen, showbSpace) -import Text.Show.Text.Utils (isInfixTypeCon, isTupleString) - -------------------------------------------------------------------------------- --- User-facing API -------------------------------------------------------------------------------- - -{- $deriveShow - -'deriveShow' automatically generates a 'T.Show' instance declaration for a @data@ -type, a @newtype@, or a data family instance. This emulates what would -(hypothetically) happen if you could attach a @deriving 'T.Show'@ clause to the end -of a data declaration. - -Here are some examples of how to derive simple data types: - -@ -{-# LANGUAGE TemplateHaskell #-} -import Text.Show.Text.TH (deriveShow) - -data Letter = A | B | C -$('deriveShow' ''Letter) -- instance Show Letter where ... - -newtype Box a = Box a -$('deriveShow' ''Box) -- instance Show a => Show (Box a) where ... -@ - -If you are using @template-haskell-2.7.0.0@ or later, 'deriveShow' can also be used -to derive 'T.Show' instances for data family instances (which requires the -@-XTypeFamilies@ extension). To do so, pass the name of a @data instance@ or @newtype -instance@ constructor to 'deriveShow'. Note that the generated code may require the -@-XFlexibleInstances@ extension. Some examples: - -@ -{-# LANGUAGE FlexibleInstances, TemplateHaskell, TypeFamilies #-} -import Text.Show.Text.TH (deriveShow) - -class AssocClass a where - data AssocData a -instance AssocClass Int where - data AssocData Int = AssocDataInt1 Int | AssocDataInt2 Int Int -$('deriveShow' 'AssocDataInt1) -- instance Show (AssocData Int) where ... --- Alternatively, one could use $(deriveShow 'AssocDataInt2) - -data family DataFam a b -newtype instance DataFam () b = DataFamB b -$('deriveShow' 'DataFamB) -- instance Show b => Show (DataFam () b) -@ - -Note that at the moment, there are some limitations: - -* The 'Name' argument to 'deriveShow' must not be a type synonym. - -* 'deriveShow' makes the assumption that all type variables of kind @*@ require a - 'T.Show' constraint when creating the type context. For example, if you have @data - Phantom a = Phantom@, then @('deriveShow' ''Phantom)@ will generate @instance - 'T.Show' a => 'T.Show' (Phantom a) where@, even though @'T.Show' a@ is not required. - If you want a proper 'T.Show' instance for @Phantom@, you will need to use - 'mkShowbPrec' (see the documentation of the 'mk' functions for more information). - -* 'deriveShow' lacks the ability to properly detect data types with higher-kinded - type parameters (e.g., @data HK f a = HK (f a)@) or with kinds other than @*@ - (e.g., @data List a (empty :: Bool)@). If you wish to derive 'T.Show' - instances for these data types, you will need to use 'mkShowbPrec' (see the - documentation of the 'mk' functions for more information). - -* Some data constructors have arguments whose 'T.Show' instance depends on a - typeclass besides 'T.Show'. For example, consider @newtype MyFixed a = MyFixed - (Fixed a)@. @'Fixed' a@ is a 'T.Show' instance only if @a@ is an instance of both - @HasResolution@ and 'T.Show'. Unfortunately, 'deriveShow' cannot infer that 'a' must - be an instance of 'HasResolution', so it cannot create a 'T.Show' instance for - @MyFixed@. However, you can use 'mkShowbPrec' to get around this (see the - documentation of the 'mk' functions for more information). - --} - --- | Generates a 'T.Show' instance declaration for the given data type or data --- family instance. --- --- /Since: 0.3/ -deriveShow :: Name -> Q [Dec] -deriveShow = deriveShowClass Show - -{- $deriveShow1 - -'deriveShow1' automatically generates a 'Show1' instance declaration for a @data@ -type, a @newtype@, or a data family instance that has at least one type variable. -This emulates what would (hypothetically) happen if you could attach a @deriving -'Show1'@ clause to the end of a data declaration. Examples: - -@ -{-# LANGUAGE TemplateHaskell #-} -import Text.Show.Text.TH (deriveShow1) - -data Stream a = Stream a (Stream a) -$('deriveShow1' ''Stream) -- instance Show1 Stream where ... - -newtype WrappedFunctor f a = WrapFunctor (f a) -$('deriveShow1' ''WrappedFunctor) -- instance Show1 f => Show1 (WrappedFunctor f) where ... -@ - -The same restrictions that apply to 'deriveShow' also apply to 'deriveShow1', with -some caveats: - -* With 'deriveShow1', the last type variable must be of kind @*@. For other ones, type - variables of kind @*@ are assumed to require a 'T.Show' context, and type variables - of kind @* -> *@ are assumed to require a 'Show1' context. For more complicated - scenarios, use 'mkShowbPrecWith'. - -* If using @DatatypeContexts@, a datatype constraint cannot mention the last type - variable. For example, @data Show a => Illegal a = Illegal a@ cannot have a derived - 'Show1' instance. - -* If the last type variable is used within a data field of a constructor, it must only - be used in the last argument of the data type constructor. For example, @data Legal a - = Legal (Either Int a)@ can have a derived 'Show1' instance, but @data Illegal a = - Illegal (Either a a)@ cannot. - -* Data family instances must be able to eta-reduce the last type variable. In other - words, if you have a instance of the form: - - @ - data family Family a1 ... an t - data instance Family e1 ... e2 v = ... - @ - - Then the following conditions must hold: - - 1. @v@ must be a type variable. - 2. @v@ must not be mentioned in any of @e1@, ..., @e2@. - -* In GHC 7.8, a bug exists that can cause problems when a data family declaration and - one of its data instances use different type variables, e.g., - - @ - data family Foo a b c - data instance Foo Int y z = Foo Int y z - $(deriveShow1 'Foo) - @ - - To avoid this issue, it is recommened that you use the same type variables in the - same positions in which they appeared in the data family declaration: - - @ - data family Foo a b c - data instance Foo Int b c = Foo Int b c - $(deriveShow 'Foo) - @ - --} - --- | Generates a 'Show1' instance declaration for the given data type or data --- family instance. --- --- /Since: 1/ -deriveShow1 :: Name -> Q [Dec] -deriveShow1 = deriveShowClass Show1 - -{- $deriveShow2 - -'deriveShow2' automatically generates a 'Show2' instance declaration for a @data@ -type, a @newtype@, or a data family instance that has at least two type variables. -This emulates what would (hypothetically) happen if you could attach a @deriving -'Show2'@ clause to the end of a data declaration. Examples: - -@ -{-# LANGUAGE TemplateHaskell #-} -import Text.Show.Text.TH (deriveShow2) - -data OneOrNone a b = OneL a | OneR b | None -$('deriveShow2' ''OneOrNone) -- instance Show2 OneOrNone where ... - -newtype WrappedBifunctor f a b = WrapBifunctor (f a b) -$('deriveShow2' ''WrappedBifunctor) -- instance Show2 f => Show2 (WrappedBifunctor f) where ... -@ - -The same restrictions that apply to 'deriveShow' and 'deriveShow1' also apply to -'deriveShow2', with some caveats: - -* With 'deriveShow2', the last type variables must both be of kind @*@. For other ones, - type variables of kind @*@ are assumed to require a 'T.Show' constraint, type - variables of kind @* -> *@ are assumed to require a 'Show1' constraint, and type - variables of kind @* -> * -> *@ are assumed to require a 'Show2' constraint. For more - complicated scenarios, use 'mkShowbPrecWith2'. - -* If using @DatatypeContexts@, a datatype constraint cannot mention either of the last - two type variables. For example, @data Show a => Illegal a b = Illegal a b@ cannot - have a derived 'Show2' instance. - -* If either of the last two type variables is used within a data field of a constructor, - it must only be used in the last two arguments of the data type constructor. For - example, @data Legal a b = Legal (Int, Int, a, b)@ can have a derived 'Show2' - instance, but @data Illegal a b = Illegal (a, b, a, b)@ cannot. - -* Data family instances must be able to eta-reduce the last two type variables. In other - words, if you have a instance of the form: - - @ - data family Family a1 ... an t1 t2 - data instance Family e1 ... e2 v1 v2 = ... - @ - - Then the following conditions must hold: - - 1. @v1@ and @v2@ must be distinct type variables. - 2. Neither @v1@ not @v2@ must be mentioned in any of @e1@, ..., @e2@. - --} - --- | Generates a 'Show2' instance declaration for the given data type or data --- family instance. --- --- /Since: 1/ -deriveShow2 :: Name -> Q [Dec] -deriveShow2 = deriveShowClass Show2 - -{- $mk - -There may be scenarios in which you want to show an arbitrary data type or data -family instance without having to make the type an instance of 'T.Show'. For these -cases, "Text.Show.Text.TH" provide several functions (all prefixed with @mk@) that -splice the appropriate lambda expression into your source code. - -As an example, suppose you have @data ADT = ADT@, which is not an instance of 'T.Show'. -With @mkShow@, you can still convert it to 'Text': - -@ -{-# LANGUAGE OverloadedStrings, TemplateHaskell #-} -import Text.Show.Text.TH (mkShow) - -whichADT :: Bool -whichADT = $(mkShow ''ADT) ADT == \"ADT\" -@ - -'mk' functions are also useful for creating 'T.Show' instances for data types with -sophisticated type parameters. For example, 'deriveShow' cannot infer the correct type -context for @newtype HigherKinded f a = HigherKinded (f a)@, since @f@ is a -higher-kinded type parameter. However, it is still possible to derive a 'T.Show' -instance for @HigherKinded@ without too much trouble using 'mkShowbPrec': - -@ -{-# LANGUAGE FlexibleContexts, TemplateHaskell #-} -import Prelude hiding (Show) -import Text.Show.Text (Show(showbPrec)) -import Text.Show.Text.TH (mkShowbPrec) - -instance Show (f a) => Show (HigherKinded f a) where - showbPrec = $(mkShowbPrec ''HigherKinded) -@ - --} - --- | Generates a lambda expression which behaves like 'T.show' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkShow :: Name -> Q Exp -mkShow name = [| toStrict . $(mkShowLazy name) |] - --- | Generates a lambda expression which behaves like 'T.showLazy' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkShowLazy :: Name -> Q Exp -mkShowLazy name = [| toLazyText . $(mkShowb name) |] - --- | Generates a lambda expression which behaves like 'T.showPrec' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkShowPrec :: Name -> Q Exp -mkShowPrec name = [| \p -> toStrict . $(mkShowPrecLazy name) p |] - --- | Generates a lambda expression which behaves like 'T.showPrecLazy' (without --- requiring a 'T.Show' instance). --- --- /Since: 0.3.1/ -mkShowPrecLazy :: Name -> Q Exp -mkShowPrecLazy name = [| \p -> toLazyText . $(mkShowbPrec name) p |] - --- | Generates a lambda expression which behaves like 'T.showList' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.5/ -mkShowList :: Name -> Q Exp -mkShowList name = [| toStrict . $(mkShowListLazy name) |] - --- | Generates a lambda expression which behaves like 'T.showListLazy' (without --- requiring a 'T.Show' instance). --- --- /Since: 0.5/ -mkShowListLazy :: Name -> Q Exp -mkShowListLazy name = [| toLazyText . $(mkShowbList name) |] - --- | Generates a lambda expression which behaves like 'T.showb' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkShowb :: Name -> Q Exp -mkShowb name = mkShowbPrec name `appE` [| zero |] - where - -- To prevent the generated TH code from having a type ascription - zero :: Int - zero = 0 - --- | Generates a lambda expression which behaves like 'T.showPrec' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkShowbPrec :: Name -> Q Exp -mkShowbPrec = mkShowbPrecClass Show - --- | Generates a lambda expression which behaves like 'T.showbPrecWith' (without --- requiring a 'Show1' instance). --- --- /Since: 1/ -mkShowbPrecWith :: Name -> Q Exp -mkShowbPrecWith = mkShowbPrecClass Show1 - --- | Generates a lambda expression which behaves like 'T.showbPrec1' (without --- requiring a 'Show1' instance). --- --- /Since: 1/ -mkShowbPrec1 :: Name -> Q Exp -mkShowbPrec1 name = [| $(mkShowbPrecWith name) showbPrec |] - --- | Generates a lambda expression which behaves like 'T.showbPrecWith2' (without --- requiring a 'Show2' instance). --- --- /Since: 1/ -mkShowbPrecWith2 :: Name -> Q Exp -mkShowbPrecWith2 = mkShowbPrecClass Show2 - --- | Generates a lambda expression which behaves like 'T.showbPrecWith2' (without --- requiring a 'Show2' instance). --- --- /Since: 1/ -mkShowbPrec2 :: Name -> Q Exp -mkShowbPrec2 name = [| $(mkShowbPrecWith2 name) showbPrec showbPrec |] - --- | Generates a lambda expression which behaves like 'T.showbList' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.5/ -mkShowbList :: Name -> Q Exp -mkShowbList name = [| showbListWith $(mkShowb name) |] - --- | Generates a lambda expression which behaves like 'T.print' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkPrint :: Name -> Q Exp -mkPrint name = [| TS.putStrLn . $(mkShow name) |] - --- | Generates a lambda expression which behaves like 'T.printLazy' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkPrintLazy :: Name -> Q Exp -mkPrintLazy name = [| TL.putStrLn . $(mkShowLazy name) |] - --- | Generates a lambda expression which behaves like 'T.hPrint' (without requiring a --- 'T.Show' instance). --- --- /Since: 0.3.1/ -mkHPrint :: Name -> Q Exp -mkHPrint name = [| \h -> TS.hPutStrLn h . $(mkShow name) |] - --- | Generates a lambda expression which behaves like 'T.hPrintLazy' (without --- requiring a 'T.Show' instance). --- --- /Since: 0.3.1/ -mkHPrintLazy :: Name -> Q Exp -mkHPrintLazy name = [| \h -> TL.hPutStrLn h . $(mkShowLazy name) |] - -------------------------------------------------------------------------------- --- Code generation -------------------------------------------------------------------------------- - --- | Derive a Show/Show1/Show2 instance declaration (depending on the ShowClass --- argument's value). -deriveShowClass :: ShowClass -> Name -> Q [Dec] -deriveShowClass sClass tyConName = do - info <- reify tyConName - case info of - TyConI{} -> deriveShowPlainTy sClass tyConName -#if MIN_VERSION_template_haskell(2,7,0) - DataConI{} -> deriveShowDataFamInst sClass tyConName - FamilyI (FamilyD DataFam _ _ _) _ -> - error $ ns ++ "Cannot use a data family name. Use a data family instance constructor instead." - FamilyI (FamilyD TypeFam _ _ _) _ -> - error $ ns ++ "Cannot use a type family name." - _ -> error $ ns ++ "The name must be of a plain type constructor or data family instance constructor." -#else - DataConI{} -> dataConIError - _ -> error $ ns ++ "The name must be of a plain type constructor." -#endif - where - ns :: String - ns = "Text.Show.Text.TH.deriveShow: " - --- | Generates a Show/Show1/Show2 instance declaration for a plain type constructor. -deriveShowPlainTy :: ShowClass -> Name -> Q [Dec] -deriveShowPlainTy sClass tyConName = - withTyCon tyConName fromCons - where - className :: Name - className = showClassNameTable sClass - - fromCons :: Cxt -> [TyVarBndr] -> [Con] -> Q [Dec] - fromCons ctxt tvbs cons = (:[]) <$> - instanceD (return instanceCxt) - (return $ AppT (ConT className) instanceType) - (showbPrecDecs droppedNbs cons) - where - (instanceCxt, instanceType, droppedNbs) = - cxtAndTypePlainTy sClass tyConName ctxt tvbs - -#if MIN_VERSION_template_haskell(2,7,0) --- | Generates a Show/Show1/Show2 instance declaration for a data family instance --- constructor. -deriveShowDataFamInst :: ShowClass -> Name -> Q [Dec] -deriveShowDataFamInst sClass dataFamInstName = - withDataFamInstCon dataFamInstName fromDec - where - className :: Name - className = showClassNameTable sClass - - fromDec :: [TyVarBndr] -> Cxt -> Name -> [Type] -> [Con] -> Q [Dec] - fromDec famTvbs ctxt parentName instTys cons = (:[]) <$> - instanceD (return instanceCxt) - (return $ AppT (ConT className) instanceType) - (showbPrecDecs droppedNbs cons) - where - (instanceCxt, instanceType, droppedNbs) = - cxtAndTypeDataFamInstCon sClass parentName ctxt famTvbs instTys -#endif - --- | Generates a declaration defining the primary function corresponding to a --- particular class (showbPrec for Show, showbPrecWith for Show1, and showbPrecWith2 --- for Show2). -showbPrecDecs :: [NameBase] -> [Con] -> [Q Dec] -showbPrecDecs nbs cons = - [ funD classFuncName - [ clause [] - (normalB $ mkShowForCons nbs cons) - [] - ] - ] - where - classFuncName :: Name - classFuncName = showbPrecNameTable . toEnum $ length nbs - --- | Generates a lambda expression which behaves like showbPrec (for Show), --- showbPrecWith (for Show1), or showbPrecWth2 (for Show2). -mkShowbPrecClass :: ShowClass -> Name -> Q Exp -mkShowbPrecClass sClass tyConName = do - info <- reify tyConName - case info of - TyConI{} -> withTyCon tyConName $ \ctxt tvbs decs -> - let (_, _, nbs) = cxtAndTypePlainTy sClass tyConName ctxt tvbs - in mkShowForCons nbs decs -#if MIN_VERSION_template_haskell(2,7,0) - DataConI{} -> withDataFamInstCon tyConName $ \famTvbs ctxt parentName instTys cons -> - let (_, _, nbs) = cxtAndTypeDataFamInstCon sClass parentName ctxt famTvbs instTys - in mkShowForCons nbs cons - FamilyI (FamilyD DataFam _ _ _) _ -> - error $ ns ++ "Cannot use a data family name. Use a data family instance constructor instead." - FamilyI (FamilyD TypeFam _ _ _) _ -> - error $ ns ++ "Cannot use a type family name." - _ -> error $ ns ++ "The name must be of a plain type constructor or data family instance constructor." -#else - DataConI{} -> dataConIError - _ -> error $ ns ++ "The name must be of a plain type constructor." -#endif - where - ns :: String - ns = "Text.Show.Text.TH.mkShowbPrec: " - --- | Generates a lambda expression for showbPrec(With)(2) for the given constructors. --- All constructors must be from the same type. -mkShowForCons :: [NameBase] -> [Con] -> Q Exp -mkShowForCons _ [] = error "Must have at least one data constructor" -mkShowForCons nbs cons = do - p <- newName "p" - value <- newName "value" - sps <- newNameList "sp" $ length nbs - let tvis = zip nbs sps - sClass = toEnum $ length nbs - lamE (map varP $ sps ++ [p, value]) - . appsE - $ [ varE $ showbPrecConstNameTable sClass - , caseE (varE value) $ map (mkShowForCon p sClass tvis) cons - ] ++ map varE sps - ++ [varE p, varE value] - --- | Generates a lambda expression for showbPrec(With)(2) for a single constructor. -mkShowForCon :: Name -> ShowClass -> [TyVarInfo] -> Con -> Q Match -mkShowForCon _ _ _ (NormalC conName []) - = match (conP conName []) - (normalB [| fromString $(stringE (parenInfixConName conName "")) |]) - [] -mkShowForCon p sClass tvis (NormalC conName [(_, argTy)]) = do - arg <- newName "arg" - - let showArg = mkShowForArg appPrec1 sClass (nameBase conName) tvis argTy arg - namedArg = [| fromString $(stringE (parenInfixConName conName " ")) <> $(showArg) |] - - match (conP conName [varP arg]) - (normalB [| showbParen ($(varE p) > $(lift appPrec)) $(namedArg) |]) - [] -mkShowForCon p sClass tvis (NormalC conName ts) = do - args <- newNameList "arg" $ length ts - - if isNonUnitTuple conName - then do - let showArgs = map (\(arg, (_, argTy)) -> mkShowForArg 0 sClass (nameBase conName) tvis argTy arg) - (zip args ts) - parenCommaArgs = [| singleton '(' |] : intersperse [| singleton ',' |] showArgs - mappendArgs = foldr (`infixApp` [| (<>) |]) - [| singleton ')' |] - parenCommaArgs - - match (conP conName $ map varP args) - (normalB mappendArgs) - [] - else do - let showArgs = map (\(arg, (_, argTy)) -> mkShowForArg appPrec1 sClass (nameBase conName) tvis argTy arg) - (zip args ts) - mappendArgs = foldr1 (\v q -> [| $(v) <> showbSpace <> $(q) |]) showArgs - namedArgs = [| fromString $(stringE (parenInfixConName conName " ")) <> $(mappendArgs) |] - - match (conP conName $ map varP args) - (normalB [| showbParen ($(varE p) > $(lift appPrec)) $(namedArgs) |]) - [] -mkShowForCon p sClass tvis (RecC conName []) = mkShowForCon p sClass tvis $ NormalC conName [] -mkShowForCon _p sClass tvis (RecC conName ts) = do - args <- newNameList "arg" $ length ts - - let showArgs = concatMap (\(arg, (argName, _, argTy)) - -> [ [| fromString $(stringE (nameBase argName ++ " = ")) |] - , mkShowForArg 0 sClass (nameBase conName) tvis argTy arg - , [| fromString ", " |] - ] - ) - (zip args ts) - braceCommaArgs = [| singleton '{' |] : take (length showArgs - 1) showArgs - mappendArgs = foldr (`infixApp` [| (<>) |]) - [| singleton '}' |] - braceCommaArgs - namedArgs = [| fromString $(stringE (parenInfixConName conName " ")) <> $(mappendArgs) |] - - match (conP conName $ map varP args) - (normalB -#if __GLASGOW_HASKELL__ >= 711 - namedArgs -#else - [| showbParen ($(varE _p) > $(lift appPrec)) $(namedArgs) |] -#endif - ) - [] -mkShowForCon p sClass tvis (InfixC (_, alTy) conName (_, arTy)) = do - al <- newName "argL" - ar <- newName "argR" - info <- reify conName - - let conPrec = case info of - DataConI _ _ _ (Fixity prec _) -> prec - other -> error $ "Text.Show.Text.TH.mkShowForCon: Unsupported type: " ++ S.show other - opName = nameBase conName - infixOpE = if isInfixTypeCon opName - then [| fromString $(stringE $ " " ++ opName ++ " " ) |] - else [| fromString $(stringE $ " `" ++ opName ++ "` ") |] - - match (infixP (varP al) conName (varP ar)) - (normalB $ appE [| showbParen ($(varE p) > conPrec) |] - [| $(mkShowForArg (conPrec + 1) sClass opName tvis alTy al) - <> $(infixOpE) - <> $(mkShowForArg (conPrec + 1) sClass opName tvis arTy ar) - |] - ) - [] -mkShowForCon p sClass tvis (ForallC tvbs _ con) = mkShowForCon p sClass (removeForalled tvbs tvis) con - --- | Generates a lambda expression for showbPrec(With)(2) for an argument of a --- constructor. -mkShowForArg :: Int - -> ShowClass - -> String - -> [TyVarInfo] - -> Type - -> Name - -> Q Exp -mkShowForArg p sClass conName tvis ty tyExpName = do - ty' <- expandSyn ty - mkShowForArg' p sClass conName tvis ty' tyExpName - --- | Generates a lambda expression for showbPrec(With)(2) for an argument of a --- constructor, after expanding all type synonyms. -mkShowForArg' :: Int - -> ShowClass - -> String - -> [TyVarInfo] - -> Type - -> Name - -> Q Exp -mkShowForArg' p _ _ _ (ConT tyName) tyExpName = -#if __GLASGOW_HASKELL__ >= 711 --- Starting with GHC 7.10, data types containing unlifted types with derived @Show@ --- instances show hashed literals with actual hash signs, and negative hashed --- literals are not surrounded with parentheses. - showE - where - tyVarE :: Q Exp - tyVarE = varE tyExpName - - showE :: Q Exp - showE | tyName == ''Char# = [| showbPrec 0 (C# $(tyVarE)) <> singleton '#' |] - | tyName == ''Double# = [| showbPrec 0 (D# $(tyVarE)) <> fromString "##" |] - | tyName == ''Float# = [| showbPrec 0 (F# $(tyVarE)) <> singleton '#' |] - | tyName == ''Int# = [| showbPrec 0 (I# $(tyVarE)) <> singleton '#' |] - | tyName == ''Word# = [| showbPrec 0 (W# $(tyVarE)) <> fromString "##" |] - | otherwise = [| showbPrec p $(tyVarE) |] -#else - [| showbPrec p $(expr) |] - where - tyVarE :: Q Exp - tyVarE = varE tyExpName - - expr :: Q Exp - expr | tyName == ''Char# = [| C# $(tyVarE) |] - | tyName == ''Double# = [| D# $(tyVarE) |] - | tyName == ''Float# = [| F# $(tyVarE) |] - | tyName == ''Int# = [| I# $(tyVarE) |] - | tyName == ''Word# = [| W# $(tyVarE) |] - | otherwise = tyVarE -#endif -mkShowForArg' p sClass conName tvis ty tyExpName = - [| $(mkShowForType sClass conName tvis ty) p $(varE tyExpName) |] - --- | Generates a lambda expression for showbPrec(With)(2) for a specific type. --- The generated expression depends on the number of type variables. --- --- 1. If the type is of kind * (T), apply showbPrec. --- 2. If the type is of kind * -> * (T a), apply showbPrecWith $(mkShowbForType a) --- 3. If the type is of kind * -> * -> * (T a b), apply --- showbPrecWith2 $(mkShowbForType a) $(mkShowbForType b) -mkShowForType :: ShowClass - -> String - -> [TyVarInfo] - -> Type - -> Q Exp -mkShowForType _ _ tvis (VarT tyName) = - case lookup (NameBase tyName) tvis of - Just spExp -> varE spExp - Nothing -> [| showbPrec |] -mkShowForType sClass conName tvis (SigT ty _) = mkShowForType sClass conName tvis ty -mkShowForType sClass conName tvis (ForallT tvbs _ ty) = mkShowForType sClass conName (removeForalled tvbs tvis) ty -mkShowForType sClass conName tvis ty = do - let tyArgs :: [Type] - tyCon :| tyArgs = unapplyTy ty - - numLastArgs :: Int - numLastArgs = min (fromEnum sClass) (length tyArgs) - - lhsArgs, rhsArgs :: [Type] - (lhsArgs, rhsArgs) = splitAt (length tyArgs - numLastArgs) tyArgs - - tyVarNameBases :: [NameBase] - tyVarNameBases = map fst tvis - - itf <- isTyFamily tyCon - if any (`mentionsNameBase` tyVarNameBases) lhsArgs - || itf && any (`mentionsNameBase` tyVarNameBases) tyArgs - then outOfPlaceTyVarError conName tyVarNameBases numLastArgs - else appsE $ [ varE . showbPrecNameTable $ toEnum numLastArgs] - ++ map (mkShowForType sClass conName tvis) rhsArgs - -------------------------------------------------------------------------------- --- Template Haskell reifying and AST manipulation -------------------------------------------------------------------------------- - --- | Extracts a plain type constructor's information. -withTyCon :: Name -- ^ Name of the plain type constructor - -> (Cxt -> [TyVarBndr] -> [Con] -> Q a) - -> Q a -withTyCon name f = do - info <- reify name - case info of - TyConI dec -> - case dec of - DataD ctxt _ tvbs cons _ -> f ctxt tvbs cons - NewtypeD ctxt _ tvbs con _ -> f ctxt tvbs [con] - other -> error $ ns ++ "Unsupported type " ++ S.show other ++ ". Must be a data type or newtype." - _ -> error $ ns ++ "The name must be of a plain type constructor." - where - ns :: String - ns = "Text.Show.Text.TH.withTyCon: " - -#if MIN_VERSION_template_haskell(2,7,0) --- | Extracts a data family name's information. -withDataFam :: Name -- ^ Name of the data family - -> ([TyVarBndr] -> [Dec] -> Q a) - -> Q a -withDataFam name f = do - info <- reify name - case info of - FamilyI (FamilyD DataFam _ tvbs _) decs -> f tvbs decs - FamilyI (FamilyD TypeFam _ _ _) _ -> - error $ ns ++ "Cannot use a type family name." - other -> error $ ns ++ "Unsupported type " ++ S.show other ++ ". Must be a data family name." - where - ns :: String - ns = "Text.Show.Text.TH.withDataFam: " - --- | Extracts a data family instance constructor's information. -withDataFamInstCon :: Name -- ^ Name of the data family instance constructor - -> ([TyVarBndr] -> Cxt -> Name -> [Type] -> [Con] -> Q a) - -> Q a -withDataFamInstCon dficName f = do - dficInfo <- reify dficName - case dficInfo of - DataConI _ _ parentName _ -> do - parentInfo <- reify parentName - case parentInfo of - FamilyI (FamilyD DataFam _ _ _) _ -> withDataFam parentName $ \famTvbs decs -> - let sameDefDec = flip find decs $ \dec -> - case dec of - DataInstD _ _ _ cons' _ -> any ((dficName ==) . constructorName) cons' - NewtypeInstD _ _ _ con _ -> dficName == constructorName con - _ -> error $ ns ++ "Must be a data or newtype instance." - - (ctxt, instTys, cons) = case sameDefDec of - Just (DataInstD ctxt' _ instTys' cons' _) -> (ctxt', instTys', cons') - Just (NewtypeInstD ctxt' _ instTys' con _) -> (ctxt', instTys', [con]) - _ -> error $ ns ++ "Could not find data or newtype instance constructor." - - in f famTvbs ctxt parentName instTys cons - _ -> error $ ns ++ "Data constructor " ++ S.show dficName ++ " is not from a data family instance." - other -> error $ ns ++ "Unsupported type " ++ S.show other ++ ". Must be a data family instance constructor." - where - ns :: String - ns = "Text.Show.Text.TH.withDataFamInstCon: " -#endif - --- | Deduces the Show/Show1/Show2 instance context, instance head, and eta-reduced --- type variables for a plain data type constructor. -cxtAndTypePlainTy :: ShowClass -- Show, Show1, or Show2 - -> Name -- The datatype's name - -> Cxt -- The datatype context - -> [TyVarBndr] -- The type variables - -> (Cxt, Type, [NameBase]) -cxtAndTypePlainTy sClass tyConName dataCxt tvbs = - if remainingLength < 0 || not (wellKinded droppedKinds) -- If we have enough well-kinded type variables - then derivingKindError sClass tyConName - else if any (`predMentionsNameBase` droppedNbs) dataCxt -- If the last type variable(s) are mentioned in a datatype context - then datatypeContextError sClass instanceType - else (instanceCxt, instanceType, droppedNbs) - where - instanceCxt :: Cxt - instanceCxt = map (applyShowConstraint) - $ filter (needsConstraint sClass . tvbKind) remaining - - instanceType :: Type - instanceType = applyTyCon tyConName $ map (VarT . tvbName) remaining - - remainingLength :: Int - remainingLength = length tvbs - fromEnum sClass - - remaining, dropped :: [TyVarBndr] - (remaining, dropped) = splitAt remainingLength tvbs - - droppedKinds :: [Kind] - droppedKinds = map tvbKind dropped - - droppedNbs :: [NameBase] - droppedNbs = map (NameBase . tvbName) dropped - -#if MIN_VERSION_template_haskell(2,7,0) --- | Deduces the Show/Show1/Show2 instance context, instance head, and eta-reduced --- type variables for a data family instnce constructor. -cxtAndTypeDataFamInstCon :: ShowClass -- Show, Show1, or Show2 - -> Name -- The data family name - -> Cxt -- The datatype context - -> [TyVarBndr] -- The data family declaration's type variables - -> [Type] -- The data family instance types - -> (Cxt, Type, [NameBase]) -cxtAndTypeDataFamInstCon sClass parentName dataCxt famTvbs instTysAndKinds = - if remainingLength < 0 || not (wellKinded droppedKinds) -- If we have enough well-kinded type variables - then derivingKindError sClass parentName - else if any (`predMentionsNameBase` droppedNbs) dataCxt -- If the last type variable(s) are mentioned in a datatype context - then datatypeContextError sClass instanceType - else if canEtaReduce remaining dropped -- If it is safe to drop the type variables - then (instanceCxt, instanceType, droppedNbs) - else etaReductionError instanceType - where - instanceCxt :: Cxt - instanceCxt = map (applyShowConstraint) - $ filter (needsConstraint sClass . tvbKind) lhsTvbs - - -- We need to make sure that type variables in the instance head which have - -- Show constrains aren't poly-kinded, e.g., - -- - -- @ - -- instance Show a => Show (Foo (a :: k)) where - -- @ - -- - -- To do this, we remove every kind ascription (i.e., strip off every 'SigT'). - instanceType :: Type - instanceType = applyTyCon parentName - $ map unSigT remaining - - remainingLength :: Int - remainingLength = length famTvbs - fromEnum sClass - - remaining, dropped :: [Type] - (remaining, dropped) = splitAt remainingLength rhsTypes - - droppedKinds :: [Kind] - droppedKinds = map tvbKind . snd $ splitAt remainingLength famTvbs - - droppedNbs :: [NameBase] - droppedNbs = map varTToNameBase dropped - - -- We need to mindful of an old GHC bug which causes kind variables appear in - -- @instTysAndKinds@ (as the name suggests) if (1) @PolyKinds@ is enabled, and - -- (2) either GHC 7.6 or 7.8 is being used (for more info, see - -- https://ghc.haskell.org/trac/ghc/ticket/9692). - -- - -- Since Template Haskell doesn't seem to have a mechanism for detecting which - -- language extensions are enabled, we do the next-best thing by counting - -- the number of distinct kind variables in the data family declaration, and - -- then dropping that number of entries from @instTysAndKinds@ - instTypes :: [Type] - instTypes = -# if __GLASGOW_HASKELL__ >= 710 || !(MIN_VERSION_template_haskell(2,8,0)) - instTysAndKinds -# else - drop (Set.size . Set.unions $ map (distinctKindVars . tvbKind) famTvbs) - instTysAndKinds -# endif - - lhsTvbs :: [TyVarBndr] - lhsTvbs = map (uncurry replaceTyVarName) - . filter (isTyVar . snd) - . take remainingLength - $ zip famTvbs rhsTypes - - -- In GHC 7.8, only the @Type@s up to the rightmost non-eta-reduced type variable - -- in @instTypes@ are provided (as a result of this extremely annoying bug: - -- https://ghc.haskell.org/trac/ghc/ticket/9692). This is pretty inconvenient, - -- as it makes it impossible to come up with the correct 'Show1' or 'Show2' - -- instances in some cases. For example, consider the following code: - -- - -- @ - -- data family Foo a b c - -- data instance Foo Int y z = Foo Int y z - -- $(deriveShow2 'Foo) - -- @ - -- - -- Due to the aformentioned bug, Template Haskell doesn't tell us the names of - -- either of type variables in the data instance (@y@ and @z@). As a result, we - -- won't know which fields of the 'Foo' constructor to apply the show functions, - -- which will result in an incorrect instance. Urgh. - -- - -- A workaround is to ensure that you use the exact same type variables, in the - -- exact same order, in the data family declaration and any data or newtype - -- instances: - -- - -- @ - -- data family Foo a b c - -- data instance Foo Int b c = Foo Int b c - -- $(deriveShow2 'Foo) - -- @ - -- - -- Thankfully, other versions of GHC don't seem to have this bug. - rhsTypes :: [Type] - rhsTypes = -# if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 - instTypes ++ map tvbToType - (drop (length instTypes) - famTvbs) -# else - instTypes -# endif -#endif - --- | Given a TyVarBndr, apply a Show, Show1, or Show2 constraint to it, depending --- on its kind. -applyShowConstraint :: TyVarBndr -> Pred -applyShowConstraint (PlainTV name) = applyClass ''T.Show name -applyShowConstraint (KindedTV name kind) = applyClass className name - where - className :: Name - className = showClassNameTable . toEnum $ numKindArrows kind - --- | Can a kind signature inhabit a Show constraint? --- --- Show: Kind k --- Show1: Kind k1 -> k2 --- Show2: Kind k1 -> k2 -> k3 -needsConstraint :: ShowClass -> Kind -> Bool -needsConstraint sClass kind = - sClass >= toEnum (numKindArrows kind) - && canRealizeKindStarChain kind - -------------------------------------------------------------------------------- --- Error messages -------------------------------------------------------------------------------- - --- | Either the given data type doesn't have enough type variables, or one of --- the type variables to be eta-reduced cannot realize kind *. -derivingKindError :: ShowClass -> Name -> a -derivingKindError sClass tyConName = error - . showString "Cannot derive well-kinded instance of form ‘" - . showString className - . showChar ' ' - . showParen True - ( showString (nameBase tyConName) - . showString " ..." - ) - . showString "‘\n\tClass " - . showString className - . showString " expects an argument of kind " - . showString (pprint . createKindChain $ fromEnum sClass) - $ "" - where - className :: String - className = nameBase $ showClassNameTable sClass - --- | One of the last type variables cannot be eta-reduced (see the canEtaReduce --- function for the criteria it would have to meet). -etaReductionError :: Type -> a -etaReductionError instanceType = error $ - "Cannot eta-reduce to an instance of form \n\tinstance (...) => " - ++ pprint instanceType - --- | The data type has a DatatypeContext which mentions one of the eta-reduced --- type variables. -datatypeContextError :: ShowClass -> Type -> a -datatypeContextError sClass instanceType = error - . showString "Can't make a derived instance of ‘" - . showString (pprint instanceType) - . showString "‘:\n\tData type ‘" - . showString className - . showString "‘ must not have a class context involving the last type argument(s)" - $ "" - where - className :: String - className = nameBase $ showClassNameTable sClass - --- | The data type mentions one of the n eta-reduced type variables in a place other --- than the last nth positions of a data type in a constructor's field. -outOfPlaceTyVarError :: String -> [NameBase] -> Int -> a -outOfPlaceTyVarError conName tyVarNames numLastArgs = error - . showString "Constructor ‘" - . showString conName - . showString "‘ must use the type variable" - . plural id (showChar 's') - . showString " " - . showsPrec 0 tyVarNames - . showString " only in the last " - . plural id (showsPrec 0 numLastArgs) - . showString "argument" - . plural id (showChar 's') - . showString " of a data type" - $ "" - where - plural :: ShowS -> ShowS -> ShowS - plural one many = case numLastArgs of - 1 -> one - _ -> many - -#if !(MIN_VERSION_template_haskell(2,7,0)) --- | Template Haskell didn't list all of a data family's instances upon reification --- until template-haskell-2.7.0.0, which is necessary for a derived Show instance --- to work. -dataConIError :: a -dataConIError = error - . showString "Cannot use a data constructor." - . showString "\n\t(Note: if you are trying to derive Show for a type family," - . showString "\n\tuse GHC >= 7.4 instead.)" - $ "" -#endif - -------------------------------------------------------------------------------- --- Expanding type synonyms -------------------------------------------------------------------------------- - --- | Expands all type synonyms in a type. Written by Dan Rosén in the --- @genifunctors@ package (licensed under BSD3). -expandSyn :: Type -> Q Type -expandSyn (ForallT tvs ctx t) = fmap (ForallT tvs ctx) $ expandSyn t -expandSyn t@AppT{} = expandSynApp t [] -expandSyn t@ConT{} = expandSynApp t [] -expandSyn (SigT t _) = expandSyn t -- Ignore kind synonyms -expandSyn t = return t - -expandSynApp :: Type -> [Type] -> Q Type -expandSynApp (AppT t1 t2) ts = do - t2' <- expandSyn t2 - expandSynApp t1 (t2':ts) -expandSynApp (ConT n) ts | nameBase n == "[]" = return $ foldl' AppT ListT ts -expandSynApp t@(ConT n) ts = do - info <- reify n - case info of - TyConI (TySynD _ tvs rhs) -> - let (ts', ts'') = splitAt (length tvs) ts - subs = mkSubst tvs ts' - rhs' = subst subs rhs - in expandSynApp rhs' ts'' - _ -> return $ foldl' AppT t ts -expandSynApp t ts = do - t' <- expandSyn t - return $ foldl' AppT t' ts - -type Subst = Map Name Type - -mkSubst :: [TyVarBndr] -> [Type] -> Subst -mkSubst vs ts = - let vs' = map un vs - un (PlainTV v) = v - un (KindedTV v _) = v - in Map.fromList $ zip vs' ts - -subst :: Subst -> Type -> Type -subst subs (ForallT v c t) = ForallT v c $ subst subs t -subst subs t@(VarT n) = fromMaybe t $ Map.lookup n subs -subst subs (AppT t1 t2) = AppT (subst subs t1) (subst subs t2) -subst subs (SigT t k) = SigT (subst subs t) k -subst _ t = t - -------------------------------------------------------------------------------- --- Class-specific constants -------------------------------------------------------------------------------- - --- | A representation of which @Show@ variant is being derived. -data ShowClass = Show | Show1 | Show2 - deriving (Enum, Eq, Ord) - -showbPrecConstNameTable :: ShowClass -> Name -showbPrecConstNameTable Show = 'showbPrecConst -showbPrecConstNameTable Show1 = 'showbPrecWithConst -showbPrecConstNameTable Show2 = 'showbPrecWith2Const - -showClassNameTable :: ShowClass -> Name -showClassNameTable Show = ''T.Show -showClassNameTable Show1 = ''Show1 -showClassNameTable Show2 = ''Show2 - -showbPrecNameTable :: ShowClass -> Name -showbPrecNameTable Show = 'showbPrec -showbPrecNameTable Show1 = 'showbPrecWith -showbPrecNameTable Show2 = 'showbPrecWith2 - --- | A type-restricted version of 'const'. This is useful when generating the lambda --- expression in 'mkShowbPrec' for a data type with only nullary constructors (since --- the expression wouldn't depend on the precedence). For example, if you had @data --- Nullary = Nullary@ and attempted to run @$(mkShowbPrec ''Nullary) Nullary@, simply --- ignoring the precedence argument would cause the type signature of @$(mkShowbPrec --- ''Nullary)@ to be @a -> Nullary -> Builder@, not @Int -> Nullary -> Builder@. -showbPrecConst :: Builder -> Int -> a -> Builder -showbPrecConst = const . const -{-# INLINE showbPrecConst #-} - -showbPrecWithConst :: Builder -> (Int -> a -> Builder) -> Int -> f a -> Builder -showbPrecWithConst = const . const . const -{-# INLINE showbPrecWithConst #-} - -showbPrecWith2Const :: Builder -> (Int -> a -> Builder) -> (Int -> b -> Builder) - -> Int -> f a b -> Builder -showbPrecWith2Const = const . const . const . const -{-# INLINE showbPrecWith2Const #-} - -------------------------------------------------------------------------------- --- NameBase -------------------------------------------------------------------------------- - --- | A wrapper around Name which only uses the 'nameBase' (not the entire Name) --- to compare for equality. For example, if you had two Names a_123 and a_456, --- they are not equal as Names, but they are equal as NameBases. --- --- This is useful when inspecting type variables, since a type variable in an --- instance context may have a distinct Name from a type variable within an --- actual constructor declaration, but we'd want to treat them as the same --- if they have the same 'nameBase' (since that's what the programmer uses to --- begin with). -newtype NameBase = NameBase { getName :: Name } - -getNameBase :: NameBase -> String -getNameBase = nameBase . getName - -instance Eq NameBase where - (==) = (==) `on` getNameBase - -instance Ord NameBase where - compare = compare `on` getNameBase - -instance S.Show NameBase where - showsPrec p = showsPrec p . getNameBase - --- | A NameBase paired with the name of its show function. For example, in a --- Show2 declaration, a list of TyVarInfos might look like [(a, 'sp1), (b, 'sp2)]. -type TyVarInfo = (NameBase, Name) - -------------------------------------------------------------------------------- --- Assorted utilities -------------------------------------------------------------------------------- - --- | Generate a list of fresh names with a common prefix, and numbered suffixes. -newNameList :: String -> Int -> Q [Name] -newNameList prefix n = mapM (newName . (prefix ++) . S.show) [1..n] - --- | Remove any occurrences of a forall-ed type variable from a list of @TyVarInfo@s. -removeForalled :: [TyVarBndr] -> [TyVarInfo] -> [TyVarInfo] -removeForalled tvbs = filter (not . foralled tvbs) - where - foralled :: [TyVarBndr] -> TyVarInfo -> Bool - foralled tvbs' tvi = fst tvi `elem` map (NameBase . tvbName) tvbs' - --- | Checks if a 'Name' represents a tuple type constructor (other than '()') -isNonUnitTuple :: Name -> Bool -isNonUnitTuple = isTupleString . nameBase - --- | Parenthesize an infix constructor name if it is being applied as a prefix --- function (e.g., data Amp a = (:&) a a) -parenInfixConName :: Name -> ShowS -parenInfixConName conName = - let conNameBase = nameBase conName - in showParen (isInfixTypeCon conNameBase) $ showString conNameBase - --- | Extracts the name from a TyVarBndr. -tvbName :: TyVarBndr -> Name -tvbName (PlainTV name) = name -tvbName (KindedTV name _) = name - --- | Extracts the kind from a TyVarBndr. -tvbKind :: TyVarBndr -> Kind -tvbKind (PlainTV _) = starK -tvbKind (KindedTV _ k) = k - --- | Replace the Name of a TyVarBndr with one from a Type (if the Type has a Name). -replaceTyVarName :: TyVarBndr -> Type -> TyVarBndr -replaceTyVarName tvb (SigT t _) = replaceTyVarName tvb t -replaceTyVarName (PlainTV _) (VarT n) = PlainTV n -replaceTyVarName (KindedTV _ k) (VarT n) = KindedTV n k -replaceTyVarName tvb _ = tvb - --- | Applies a typeclass constraint to a type. -applyClass :: Name -> Name -> Pred -#if MIN_VERSION_template_haskell(2,10,0) -applyClass con t = AppT (ConT con) (VarT t) -#else -applyClass con t = ClassP con [VarT t] -#endif - --- | Checks to see if the last types in a data family instance can be safely eta- --- reduced (i.e., dropped), given the other types. This checks for three conditions: --- --- (1) All of the dropped types are type variables --- (2) All of the dropped types are distinct --- (3) None of the remaining types mention any of the dropped types -canEtaReduce :: [Type] -> [Type] -> Bool -canEtaReduce remaining dropped = - all isTyVar dropped - && allDistinct nbs -- Make sure not to pass something of type [Type], since Type - -- didn't have an Ord instance until template-haskell-2.10.0.0 - && not (any (`mentionsNameBase` nbs) remaining) - where - nbs :: [NameBase] - nbs = map varTToNameBase dropped - --- | Extract the Name from a type variable. -varTToName :: Type -> Name -varTToName (VarT n) = n -varTToName (SigT t _) = varTToName t -varTToName _ = error "Not a type variable!" - --- | Extract the NameBase from a type variable. -varTToNameBase :: Type -> NameBase -varTToNameBase = NameBase . varTToName - --- | Peel off a kind signature from a Type (if it has one). -unSigT :: Type -> Type -unSigT (SigT t _) = t -unSigT t = t - --- | Is the given type a variable? -isTyVar :: Type -> Bool -isTyVar (VarT _) = True -isTyVar (SigT t _) = isTyVar t -isTyVar _ = False - --- | Is the given type a type family constructor (and not a data family constructor)? -isTyFamily :: Type -> Q Bool -isTyFamily (ConT n) = do - info <- reify n - return $ case info of -#if MIN_VERSION_template_haskell(2,7,0) - FamilyI (FamilyD TypeFam _ _ _) _ -> True -#else - TyConI (FamilyD TypeFam _ _ _) -> True -#endif - _ -> False -isTyFamily _ = return False - --- | Are all of the items in a list (which have an ordering) distinct? --- --- This uses Set (as opposed to nub) for better asymptotic time complexity. -allDistinct :: Ord a => [a] -> Bool -allDistinct = allDistinct' Set.empty - where - allDistinct' :: Ord a => Set a -> [a] -> Bool - allDistinct' uniqs (x:xs) - | x `Set.member` uniqs = False - | otherwise = allDistinct' (Set.insert x uniqs) xs - allDistinct' _ _ = True - --- | Does the given type mention any of the NameBases in the list? -mentionsNameBase :: Type -> [NameBase] -> Bool -mentionsNameBase = go Set.empty - where - go :: Set NameBase -> Type -> [NameBase] -> Bool - go foralls (ForallT tvbs _ t) nbs = - go (foralls `Set.union` Set.fromList (map (NameBase . tvbName) tvbs)) t nbs - go foralls (AppT t1 t2) nbs = go foralls t1 nbs || go foralls t2 nbs - go foralls (SigT t _) nbs = go foralls t nbs - go foralls (VarT n) nbs = varNb `elem` nbs && not (varNb `Set.member` foralls) - where - varNb = NameBase n - go _ _ _ = False - --- | Does an instance predicate mention any of the NameBases in the list? -predMentionsNameBase :: Pred -> [NameBase] -> Bool -#if MIN_VERSION_template_haskell(2,10,0) -predMentionsNameBase = mentionsNameBase -#else -predMentionsNameBase (ClassP _ tys) nbs = any (`mentionsNameBase` nbs) tys -predMentionsNameBase (EqualP t1 t2) nbs = mentionsNameBase t1 nbs || mentionsNameBase t2 nbs -#endif - --- | The number of arrows that compose the spine of a kind signature --- (e.g., (* -> *) -> k -> * has two arrows on its spine). -numKindArrows :: Kind -> Int -numKindArrows k = length (uncurryKind k) - 1 - --- | Construct a type via curried application. -applyTy :: Type -> [Type] -> Type -applyTy = foldl' AppT - --- | Fully applies a type constructor to its type variables. -applyTyCon :: Name -> [Type] -> Type -applyTyCon = applyTy . ConT - --- | Split an applied type into its individual components. For example, this: --- --- @ --- Either Int Char --- @ --- --- would split to this: --- --- @ --- [Either, Int, Char] --- @ -unapplyTy :: Type -> NonEmpty Type -unapplyTy = NE.reverse . go - where - go :: Type -> NonEmpty Type - go (AppT t1 t2) = t2 <| go t1 - go (SigT t _) = go t - go t = t :| [] - --- | Split a type signature by the arrows on its spine. For example, this: --- --- @ --- (Int -> String) -> Char -> () --- @ --- --- would split to this: --- --- @ --- [Int -> String, Char, ()] --- @ -uncurryTy :: Type -> NonEmpty Type -uncurryTy (AppT (AppT ArrowT t1) t2) = t1 <| uncurryTy t2 -uncurryTy (SigT t _) = uncurryTy t -uncurryTy t = t :| [] - --- | Like uncurryType, except on a kind level. -uncurryKind :: Kind -> NonEmpty Kind -#if MIN_VERSION_template_haskell(2,8,0) -uncurryKind = uncurryTy -#else -uncurryKind (ArrowK k1 k2) = k1 <| uncurryKind k2 -uncurryKind k = k :| [] -#endif - -wellKinded :: [Kind] -> Bool -wellKinded = all canRealizeKindStar - --- | Of form k1 -> k2 -> ... -> kn, where k is either a single kind variable or *. -canRealizeKindStarChain :: Kind -> Bool -canRealizeKindStarChain = all canRealizeKindStar . uncurryKind - -canRealizeKindStar :: Kind -> Bool -canRealizeKindStar k = case uncurryKind k of - k' :| [] -> case k' of -#if MIN_VERSION_template_haskell(2,8,0) - StarT -> True - (VarT _) -> True -- Kind k can be instantiated with * -#else - StarK -> True -#endif - _ -> False - _ -> False - -createKindChain :: Int -> Kind -createKindChain = go starK - where - go :: Kind -> Int -> Kind - go k !0 = k -#if MIN_VERSION_template_haskell(2,8,0) - go k !n = go (AppT (AppT ArrowT StarT) k) (n - 1) -#else - go k !n = go (ArrowK StarK k) (n - 1) -#endif - -# if MIN_VERSION_template_haskell(2,8,0) && __GLASGOW_HASKELL__ < 710 -distinctKindVars :: Kind -> Set Name -distinctKindVars (AppT k1 k2) = distinctKindVars k1 `Set.union` distinctKindVars k2 -distinctKindVars (SigT k _) = distinctKindVars k -distinctKindVars (VarT k) = Set.singleton k -distinctKindVars _ = Set.empty -#endif - -#if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 -tvbToType :: TyVarBndr -> Type -tvbToType (PlainTV n) = VarT n -tvbToType (KindedTV n k) = SigT (VarT n) k -#endif - -#if MIN_VERSION_template_haskell(2,7,0) --- | Extracts the name of a constructor. -constructorName :: Con -> Name -constructorName (NormalC name _ ) = name -constructorName (RecC name _ ) = name -constructorName (InfixC _ name _ ) = name -constructorName (ForallC _ _ con) = constructorName con -#endif
− src/Text/Show/Text/Text/Read.hs
@@ -1,79 +0,0 @@-{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -{-| -Module: Text.Show.Text.Text.Read -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Monomorphic 'Show' function for 'Lexeme' (and 'Number', if using a -recent-enough version of @base@). - -/Since: 0.3/ --} -module Text.Show.Text.Text.Read ( - showbLexemePrec -#if MIN_VERSION_base(4,7,0) - , showbNumberPrec -#endif - ) where - -import Data.Text.Lazy.Builder (Builder) - -import Prelude hiding (Show) - -import Text.Read.Lex (Lexeme(..)) -#if MIN_VERSION_base(4,7,0) -import Text.Read.Lex (Number) -#endif -import Text.Show.Text.Classes (Show(showbPrec), showbUnaryWith) -#if MIN_VERSION_base(4,6,0) -import Text.Show.Text.Classes (FromStringShow(..)) -#else -import Text.Show.Text.Data.Integral () -import Text.Show.Text.Data.Ratio () -#endif -import Text.Show.Text.Data.Char () -import Text.Show.Text.Data.List () - -#include "inline.h" - --- | Convert a 'Lexeme' to a 'Builder' with the given precedence. --- --- /Since: 0.3/ -showbLexemePrec :: Int -> Lexeme -> Builder -showbLexemePrec p (Char c) = showbUnaryWith showbPrec "Char" p c -showbLexemePrec p (String s) = showbUnaryWith showbPrec "String" p s -showbLexemePrec p (Punc pun) = showbUnaryWith showbPrec "Punc" p pun -showbLexemePrec p (Ident i) = showbUnaryWith showbPrec "Ident" p i -showbLexemePrec p (Symbol s) = showbUnaryWith showbPrec "Symbol" p s -#if MIN_VERSION_base(4,6,0) -showbLexemePrec p (Number n) = showbUnaryWith showbPrec "Number" p $ FromStringShow n -#else -showbLexemePrec p (Int i) = showbUnaryWith showbPrec "Int" p i -showbLexemePrec p (Rat r) = showbUnaryWith showbPrec "Rat" p r -#endif -showbLexemePrec _ EOF = "EOF" - -#if MIN_VERSION_base(4,7,0) --- | Convert a 'Number' to a 'Builder' with the given precedence. --- This function is only available with @base-4.7.0.0@ or later. --- --- /Since: 0.3/ -showbNumberPrec :: Int -> Number -> Builder -showbNumberPrec p = showbPrec p . FromStringShow -{-# INLINE showbNumberPrec #-} -#endif - -instance Show Lexeme where - showbPrec = showbLexemePrec - INLINE_INST_FUN(showbPrec) - -#if MIN_VERSION_base(4,7,0) -instance Show Number where - showbPrec = showbNumberPrec - {-# INLINE showbPrec #-} -#endif
− src/Text/Show/Text/Utils.hs
@@ -1,80 +0,0 @@-{-# LANGUAGE MagicHash #-} - -{-| -Module: Text.Show.Text.Utils -Copyright: (C) 2014-2015 Ryan Scott -License: BSD-style (see the file LICENSE) -Maintainer: Ryan Scott -Stability: Provisional -Portability: GHC - -Miscellaneous utility functions. --} -module Text.Show.Text.Utils where - -import Data.Int (Int64) -import Data.Text (Text) -import Data.Monoid.Compat ((<>)) -import Data.Text.Lazy (length, toStrict, unpack) -import Data.Text.Lazy.Builder (Builder, singleton, toLazyText) - -import GHC.Exts (Char(C#), Int(I#)) -import GHC.Prim ((+#), chr#, ord#) - -import Prelude () -import Prelude.Compat hiding (length) - --- | Unsafe conversion for decimal digits. -i2d :: Int -> Char -i2d (I# i#) = C# (chr# (ord# '0'# +# i#)) -{-# INLINE i2d #-} - --- | Checks if a 'String' names a valid Haskell infix type constructor (i.e., does --- it begin with a colon?). -isInfixTypeCon :: String -> Bool -isInfixTypeCon (':':_) = True -isInfixTypeCon _ = False -{-# INLINE isInfixTypeCon #-} - --- | Checks if a 'String' represents a tuple (other than '()') -isTupleString :: String -> Bool -isTupleString ('(':',':_) = True -isTupleString _ = False -{-# INLINE isTupleString #-} - --- | Computes the length of a 'Builder'. --- --- /Since: 0.3/ -lengthB :: Builder -> Int64 -lengthB = length . toLazyText -{-# INLINE lengthB #-} - --- | Convert a 'Builder' to a 'String' (without surrounding it with double quotes, --- as 'show' would). --- --- /Since: 0.4.1/ -toString :: Builder -> String -toString = unpack . toLazyText -{-# INLINE toString #-} - --- | Convert a 'Builder' to a strict 'Text'. --- --- /Since: 0.4.1/ -toText :: Builder -> Text -toText = toStrict . toLazyText -{-# INLINE toText #-} - --- | Merges several 'Builder's, separating them by newlines. --- --- /Since: 0.1/ -unlinesB :: [Builder] -> Builder -unlinesB (b:bs) = b <> singleton '\n' <> unlinesB bs -unlinesB [] = mempty - --- | Merges several 'Builder's, separating them by spaces. --- --- /Since: 0.1/ -unwordsB :: [Builder] -> Builder -unwordsB (b:bs@(_:_)) = b <> singleton ' ' <> unwordsB bs -unwordsB [b] = b -unwordsB [] = mempty
+ src/TextShow.hs view
@@ -0,0 +1,67 @@+{-| +Module: TextShow +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Efficiently convert from values to 'Text' via 'Builder's. + +/Since: 2/ +-} +module TextShow ( + -- * The @TextShow@ classes + -- ** 'TextShow' + TextShow(..) + , showt + , showtl + , showtPrec + , showtlPrec + , showtList + , showtlList + , showbParen + , showbSpace + -- ** 'TextShow1' + , TextShow1(..) + , showbPrec1 + , showbUnaryWith + -- ** 'TextShow2' + , TextShow2(..) + , showbPrec2 + , showbBinaryWith + -- * 'Builder's + -- ** The 'Builder' type + , Builder + , toText + , toLazyText + , toLazyTextWith + , toString + -- ** Constructing 'Builder's + , singleton + , fromText + , fromLazyText + , fromString + -- ** Flushing the buffer state + , flush + -- ** 'Builder' utility functions + , lengthB + , unlinesB + , unwordsB + -- * Printing values + , printT + , printTL + , hPrintT + , hPrintTL + -- * Conversion between 'TextShow' and string @Show@ + , FromStringShow(..) + , FromTextShow(..) + ) where + +import Data.Text.Lazy.Builder + +import Prelude () + +import TextShow.Classes +import TextShow.Instances () +import TextShow.Utils (toString, toText, lengthB, unlinesB, unwordsB)
+ src/TextShow/Classes.hs view
@@ -0,0 +1,377 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveFoldable #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE OverloadedStrings #-} + +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE DeriveGeneric #-} +#else +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} +#endif + +#if __GLASGOW_HASKELL__ >= 708 +{-# LANGUAGE AutoDeriveTypeable #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE StandaloneDeriving #-} +#endif +{-| +Module: TextShow.Classes +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +The 'TextShow', 'TextShow1', and 'TextShow2' typeclasses. +-} +module TextShow.Classes where + +import Data.Data (Data, Typeable) +import Data.Monoid.Compat ((<>)) +import Data.Text as TS (Text) +import qualified Data.Text.IO as TS (putStrLn, hPutStrLn) +import qualified Data.Text.Lazy as TL (Text) +import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn) +import Data.Text.Lazy (toStrict) +import Data.Text.Lazy.Builder (Builder, fromString, singleton, toLazyText) + +#if __GLASGOW_HASKELL__ >= 702 +import GHC.Generics (Generic) +# if __GLASGOW_HASKELL__ >= 706 +import GHC.Generics (Generic1) +# endif +#else +import qualified Generics.Deriving.TH as Generics (deriveAll) +#endif +import GHC.Show (appPrec, appPrec1) + +import Prelude () +import Prelude.Compat + +import System.IO (Handle) + +import Text.Read (Read(..), readListPrecDefault) + +import TextShow.Utils (toString) + +#include "inline.h" + +------------------------------------------------------------------------------- + +-- | Conversion of values to @Text@. Because there are both strict and lazy @Text@ +-- variants, the 'TextShow' class deliberately avoids using @Text@ in its functions. +-- Instead, 'showbPrec', 'showb', and 'showbList' all return 'Builder', an +-- efficient intermediate form that can be converted to either kind of @Text@. +-- +-- 'Builder' is a 'Monoid', so it is useful to use the 'mappend' (or '<>') function +-- to combine 'Builder's when creating 'TextShow' instances. As an example: +-- +-- @ +-- import Data.Monoid +-- import TextShow +-- +-- data Example = Example Int Int +-- instance TextShow Example where +-- showb (Example i1 i2) = showb i1 <> showbSpace <> showb i2 +-- @ +-- +-- If you do not want to create 'TextShow' instances manually, you can alternatively +-- use the "TextShow.TH" module to automatically generate default 'TextShow' +-- instances using Template Haskell, or the "TextShow.Generic" module to +-- quickly define 'TextShow' instances using 'genericShowbPrec'. +-- +-- /Since: 2/ +class TextShow a where + -- | Convert a value to a 'Builder' with the given predence. + -- + -- /Since: 2/ + showbPrec :: Int -- ^ The operator precedence of the enclosing context (a number + -- from @0@ to @11@). Function application has precedence @10@. + -> a -- ^ The value to be converted to a 'String'. + -> Builder + showbPrec _ = showb + + -- | A specialized variant of 'showbPrec' using precedence context zero. + -- + -- /Since: 2/ + showb :: a -> Builder + showb = showbPrec 0 + + -- | Allows for specialized display of lists. This is used, for example, when + -- showing lists of 'Char's. + -- + -- /Since: 2/ + showbList :: [a] -> Builder + showbList = showbListWith showb + +#if __GLASGOW_HASKELL__ >= 708 + {-# MINIMAL showbPrec | showb #-} + +deriving instance Typeable TextShow +#endif + +-- | Constructs a strict 'TS.Text' from a single value. +-- +-- /Since: 2/ +showt :: TextShow a => a -> TS.Text +showt = toStrict . showtl +{-# INLINE showt #-} + +-- | Constructs a lazy 'TL.Text' from a single value. +-- +-- /Since: 2/ +showtl :: TextShow a => a -> TL.Text +showtl = toLazyText . showb +{-# INLINE showtl #-} + +-- | Constructs a strict 'TS.Text' from a single value with the given precedence. +-- +-- /Since: 2/ +showtPrec :: TextShow a => Int -> a -> TS.Text +showtPrec p = toStrict . showtlPrec p +{-# INLINE showtPrec #-} + +-- | Constructs a lazy 'TL.Text' from a single value with the given precedence. +-- +-- /Since: 2/ +showtlPrec :: TextShow a => Int -> a -> TL.Text +showtlPrec p = toLazyText . showbPrec p +{-# INLINE showtlPrec #-} + +-- | Construct a strict 'TS.Text' from a list of values. +-- +-- /Since: 2/ +showtList :: TextShow a => [a] -> TS.Text +showtList = toStrict . showtlList +{-# INLINE showtList #-} + +-- | Construct a lazy 'TL.Text' from a list of values. +-- +-- /Since: 2/ +showtlList :: TextShow a => [a] -> TL.Text +showtlList = toLazyText . showbList +{-# INLINE showtlList #-} + +-- | Surrounds 'Builder' output with parentheses if the 'Bool' parameter is 'True'. +-- +-- /Since: 2/ +showbParen :: Bool -> Builder -> Builder +showbParen p builder | p = singleton '(' <> builder <> singleton ')' + | otherwise = builder +{-# INLINE showbParen #-} + +-- | Construct a 'Builder' containing a single space character. +-- +-- /Since: 2/ +showbSpace :: Builder +showbSpace = singleton ' ' + +-- | Converts a list of values into a 'Builder' in which the values are surrounded +-- by square brackets and each value is separated by a comma. The function argument +-- controls how each element is shown. + +-- @'showbListWith' 'showb'@ is the default implementation of 'showbList' save for +-- a few special cases (e.g., 'String'). +-- +-- /Since: 2/ +showbListWith :: (a -> Builder) -> [a] -> Builder +showbListWith _ [] = "[]" +showbListWith showbx (x:xs) = singleton '[' <> showbx x <> go xs -- "[.. + where + go (y:ys) = singleton ',' <> showbx y <> go ys -- ..,.. + go [] = singleton ']' -- ..]" +{-# INLINE showbListWith #-} + +-- | Writes a value's strict 'TS.Text' representation to the standard output, followed +-- by a newline. +-- +-- /Since: 2/ +printT :: TextShow a => a -> IO () +printT = TS.putStrLn . showt +{-# INLINE printT #-} + +-- | Writes a value's lazy 'TL.Text' representation to the standard output, followed +-- by a newline. +-- +-- /Since: 2/ +printTL :: TextShow a => a -> IO () +printTL = TL.putStrLn . showtl +{-# INLINE printTL #-} + +-- | Writes a value's strict 'TS.Text' representation to a file handle, followed +-- by a newline. +-- +-- /Since: 2/ +hPrintT :: TextShow a => Handle -> a -> IO () +hPrintT h = TS.hPutStrLn h . showt +{-# INLINE hPrintT #-} + +-- | Writes a value's lazy 'TL.Text' representation to a file handle, followed +-- by a newline. +-- +-- /Since: 2/ +hPrintTL :: TextShow a => Handle -> a -> IO () +hPrintTL h = TL.hPutStrLn h . showtl +{-# INLINE hPrintTL #-} + +------------------------------------------------------------------------------- + +-- | Lifting of the 'TextShow' class to unary type constructors. +-- +-- /Since: 2/ +class TextShow1 f where + -- | Lifts a 'showbPrec' function through the type constructor. + -- + -- /Since: 2/ + showbPrecWith :: (Int -> a -> Builder) -> Int -> f a -> Builder + +#if __GLASGOW_HASKELL__ >= 708 +deriving instance Typeable TextShow1 +#endif + +-- | Lift the standard 'showbPrec' function through the type constructor. +-- +-- /Since: 2/ +showbPrec1 :: (TextShow1 f, TextShow a) => Int -> f a -> Builder +showbPrec1 = showbPrecWith showbPrec +{-# INLINE showbPrec1 #-} + +-- | @'showbUnaryWith' sp n p x@ produces the 'Builder' representation of a unary data +-- constructor with name @n@ and argument @x@, in precedence context @p@, using the +-- function @sp@ to show occurrences of the type argument. +-- +-- /Since: 2/ +showbUnaryWith :: (Int -> a -> Builder) -> Builder -> Int -> a -> Builder +showbUnaryWith sp nameB p x = showbParen (p > appPrec) $ + nameB <> showbSpace <> sp appPrec1 x +{-# INLINE showbUnaryWith #-} + +------------------------------------------------------------------------------- + +-- | Lifting of the 'TextShow' class to binary type constructors. +-- +-- /Since: 2/ +class TextShow2 f where + -- | Lifts 'showbPrec' functions through the type constructor. + -- + -- /Since: 2/ + showbPrecWith2 :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> + Int -> f a b -> Builder + +#if __GLASGOW_HASKELL__ >= 708 +deriving instance Typeable TextShow2 +#endif + +-- | Lift two 'showbPrec' functions through the type constructor. +-- +-- /Since: 2/ +showbPrec2 :: (TextShow2 f, TextShow a, TextShow b) => Int -> f a b -> Builder +showbPrec2 = showbPrecWith2 showbPrec showbPrec +{-# INLINE showbPrec2 #-} + +-- | @'showbBinaryWith' sp n p x y@ produces the 'Builder' representation of a binary +-- data constructor with name @n@ and arguments @x@ and @y@, in precedence context +-- @p@, using the functions @sp1@ and @sp2@ to show occurrences of the type arguments. +-- +-- /Since: 2/ +showbBinaryWith :: (Int -> a -> Builder) -> (Int -> b -> Builder) -> + Builder -> Int -> a -> b -> Builder +showbBinaryWith sp1 sp2 nameB p x y = showbParen (p > appPrec) $ nameB + <> showbSpace <> sp1 appPrec1 x + <> showbSpace <> sp2 appPrec1 y +{-# INLINE showbBinaryWith #-} + +------------------------------------------------------------------------------- + +-- | The 'TextShow' instance for 'FromStringShow' is based on its @String@ +-- 'Show' instance. That is, +-- +-- @ +-- showbPrec p ('FromStringShow' x) = 'fromString' (showsPrec p x "") +-- @ +-- +-- /Since: 2/ +newtype FromStringShow a = FromStringShow { fromStringShow :: a } + deriving ( Data + , Eq + , Foldable + , Functor +#if __GLASGOW_HASKELL__ >= 702 + , Generic +# if __GLASGOW_HASKELL__ >= 706 + , Generic1 +# endif +#endif + , Ord + , Traversable + , Typeable + ) + +instance Read a => Read (FromStringShow a) where + readPrec = FromStringShow <$> readPrec + INLINE_INST_FUN(readPrec) + + readListPrec = readListPrecDefault + INLINE_INST_FUN(readListPrec) + +instance Show a => TextShow (FromStringShow a) where + showbPrec p (FromStringShow x) = fromString $ showsPrec p x "" + INLINE_INST_FUN(showbPrec) + +instance Show a => Show (FromStringShow a) where + showsPrec p (FromStringShow x) = showsPrec p x + INLINE_INST_FUN(showsPrec) + +-- | The @String@ 'Show' instance for 'FromTextShow' is based on its +-- 'TextShow' instance. That is, +-- +-- @ +-- showsPrec p ('FromTextShow' x) = 'showString' ('toString' (showbPrec p x)) +-- @ +-- +-- /Since: 2/ +newtype FromTextShow a = FromTextShow { fromTextShow :: a } + deriving ( Data + , Eq + , Foldable + , Functor +#if __GLASGOW_HASKELL__ >= 702 + , Generic +# if __GLASGOW_HASKELL__ >= 706 + , Generic1 +# endif +#endif + , Ord + , Traversable + , Typeable + ) + +instance Read a => Read (FromTextShow a) where + readPrec = FromTextShow <$> readPrec + INLINE_INST_FUN(readPrec) + + readListPrec = readListPrecDefault + INLINE_INST_FUN(readListPrec) + +instance TextShow a => Show (FromTextShow a) where + showsPrec p (FromTextShow x) = showString . toString $ showbPrec p x + INLINE_INST_FUN(showsPrec) + +instance TextShow a => TextShow (FromTextShow a) where + showbPrec = showbPrec1 + INLINE_INST_FUN(showbPrec) + +instance TextShow1 FromTextShow where + showbPrecWith sp p (FromTextShow x) = sp p x + INLINE_INST_FUN(showbPrecWith) + +------------------------------------------------------------------------------- + +#if __GLASGOW_HASKELL__ < 702 +$(Generics.deriveAll ''FromStringShow) +$(Generics.deriveAll ''FromTextShow) +#endif
+ src/TextShow/Control/Applicative.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Control.Applicative +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for 'Const' and 'ZipList'. + +/Since: 2/ +-} +module TextShow.Control.Applicative (showbConstPrecWith, showbZipListPrecWith) where + +import Control.Applicative (Const(..), ZipList) + +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (TextShow(showbPrec), TextShow1(..), + TextShow2(..), showbUnaryWith) +import TextShow.Data.List () +import TextShow.TH.Internal (deriveTextShow, deriveTextShow1) + +-- | Convert a 'Const' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbConstPrecWith :: (Int -> a -> Builder) -> Int -> Const a b -> Builder +showbConstPrecWith sp = showbPrecWith2 sp undefined + +-- | Convert a 'ZipList' to a 'Builder' with the given show function precedence. +-- +-- /Since: 2/ +showbZipListPrecWith :: (Int -> a -> Builder) -> Int -> ZipList a -> Builder +showbZipListPrecWith = showbPrecWith + +instance TextShow a => TextShow (Const a b) where + showbPrec = showbPrecWith undefined + +instance TextShow a => TextShow1 (Const a) where + showbPrecWith = showbPrecWith2 showbPrec + +instance TextShow2 Const where + showbPrecWith2 sp1 _ p (Const x) = showbUnaryWith sp1 "Const" p x + +$(deriveTextShow ''ZipList) +$(deriveTextShow1 ''ZipList)
+ src/TextShow/Control/Concurrent.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Control.Concurrent +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for concurrency-related data types. + +/Since: 2/ +-} +module TextShow.Control.Concurrent ( + showbThreadIdPrec + , showbThreadStatusPrec + , showbBlockReason + ) where + +import Data.Text.Lazy.Builder (Builder) + +import GHC.Conc (BlockReason, ThreadId, ThreadStatus) + +import TextShow.Classes (TextShow(showb, showbPrec), FromStringShow(..)) +import TextShow.TH.Internal (deriveTextShow) + +#include "inline.h" + +-- | Convert a 'ThreadId' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbThreadIdPrec :: Int -> ThreadId -> Builder +showbThreadIdPrec p = showbPrec p . FromStringShow +{-# INLINE showbThreadIdPrec #-} + +-- | Convert a 'ThreadStatus' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbThreadStatusPrec :: Int -> ThreadStatus -> Builder +showbThreadStatusPrec = showbPrec +{-# INLINE showbThreadStatusPrec #-} + +-- | Convert a 'BlockReason' to a 'Builder'. +-- +-- /Since: 2/ +showbBlockReason :: BlockReason -> Builder +showbBlockReason = showb +{-# INLINE showbBlockReason #-} + +instance TextShow ThreadId where + showbPrec = showbThreadIdPrec + INLINE_INST_FUN(showbPrec) + +$(deriveTextShow ''ThreadStatus) +$(deriveTextShow ''BlockReason)
+ src/TextShow/Control/Exception.hs view
@@ -0,0 +1,299 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Control.Exception +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for 'Exception's. + +/Since: 2/ +-} +module TextShow.Control.Exception ( + showbSomeExceptionPrec + , showbIOException + , showbArithException + , showbArrayException + , showbAssertionFailed +#if MIN_VERSION_base(4,7,0) + , showbSomeAsyncException +#endif + , showbAsyncException + , showbNonTermination + , showbNestedAtomically + , showbBlockedIndefinitelyOnMVar + , showbBlockedIndefinitelyOnSTM +#if MIN_VERSION_base(4,8,0) + , showbAllocationLimitExceeded +#endif + , showbDeadlock + , showbNoMethodError + , showbPatternMatchFail + , showbRecConError + , showbRecSelError + , showbRecUpdError + , showbErrorCall + , showbMaskingState + ) where + +import Control.Exception.Base + +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, fromString) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(showb, showbPrec), FromStringShow(..)) +import TextShow.TH.Internal (deriveTextShow) + +#include "inline.h" + +-- | Convert a 'SomeException' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbSomeExceptionPrec :: Int -> SomeException -> Builder +showbSomeExceptionPrec p (SomeException e) = showbPrec p $ FromStringShow e +{-# INLINE showbSomeExceptionPrec #-} + +-- | Convert an 'IOException' to a 'Builder'. +-- +-- /Since: 2/ +showbIOException :: IOException -> Builder +showbIOException = showb . FromStringShow +{-# INLINE showbIOException #-} + +-- | Convert an 'ArithException' to a 'Builder'. +-- +-- /Since: 2/ +showbArithException :: ArithException -> Builder +showbArithException Overflow = "arithmetic overflow" +showbArithException Underflow = "arithmetic underflow" +showbArithException LossOfPrecision = "loss of precision" +showbArithException DivideByZero = "divide by zero" +showbArithException Denormal = "denormal" +#if MIN_VERSION_base(4,6,0) +showbArithException RatioZeroDenominator = "Ratio has zero denominator" +#endif + +-- | Convert an 'ArrayException' to a 'Builder'. +-- +-- /Since: 2/ +showbArrayException :: ArrayException -> Builder +showbArrayException (IndexOutOfBounds s) + = "array index out of range" + <> (if not $ null s then ": " <> fromString s + else mempty) +showbArrayException (UndefinedElement s) + = "undefined array element" + <> (if not $ null s then ": " <> fromString s + else mempty) +{-# INLINE showbArrayException #-} + +-- | Convert an 'AssertionFailed' exception to a 'Builder'. +-- +-- /Since: 2/ +showbAssertionFailed :: AssertionFailed -> Builder +showbAssertionFailed (AssertionFailed err) = fromString err +{-# INLINE showbAssertionFailed #-} + +#if MIN_VERSION_base(4,7,0) +-- | Convert a 'SomeAsyncException' value to a 'Builder'. +-- This function is only available with @base-4.7.0.0@ or later. +-- +-- /Since: 2/ +showbSomeAsyncException :: SomeAsyncException -> Builder +showbSomeAsyncException (SomeAsyncException e) = showb $ FromStringShow e +{-# INLINE showbSomeAsyncException #-} +#endif + +-- | Convert an 'AsyncException' to a 'Builder'. +-- +-- /Since: 2/ +showbAsyncException :: AsyncException -> Builder +showbAsyncException StackOverflow = "stack overflow" +showbAsyncException HeapOverflow = "heap overflow" +showbAsyncException ThreadKilled = "thread killed" +showbAsyncException UserInterrupt = "user interrupt" +{-# INLINE showbAsyncException #-} + +-- | Convert a 'NonTermination' exception to a 'Builder'. +-- +-- /Since: 2/ +showbNonTermination :: NonTermination -> Builder +showbNonTermination NonTermination = "<<loop>>" +{-# INLINE showbNonTermination #-} + +-- | Convert a 'NestedAtomically' exception to a 'Builder'. +-- +-- /Since: 2/ +showbNestedAtomically :: NestedAtomically -> Builder +showbNestedAtomically NestedAtomically = "Control.Concurrent.STM.atomically was nested" +{-# INLINE showbNestedAtomically #-} + +-- | Convert a 'BlockedIndefinitelyOnMVar' exception to a 'Builder'. +-- +-- /Since: 2/ +showbBlockedIndefinitelyOnMVar :: BlockedIndefinitelyOnMVar -> Builder +showbBlockedIndefinitelyOnMVar BlockedIndefinitelyOnMVar = "thread blocked indefinitely in an MVar operation" +{-# INLINE showbBlockedIndefinitelyOnMVar #-} + +-- | Convert a 'BlockedIndefinitelyOnSTM' exception to a 'Builder'. +-- +-- /Since: 2/ +showbBlockedIndefinitelyOnSTM :: BlockedIndefinitelyOnSTM -> Builder +showbBlockedIndefinitelyOnSTM BlockedIndefinitelyOnSTM = "thread blocked indefinitely in an STM transaction" +{-# INLINE showbBlockedIndefinitelyOnSTM #-} + +#if MIN_VERSION_base(4,8,0) +-- | Convert an 'AllocationLimitExceeded' exception to a 'Builder'. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbAllocationLimitExceeded :: AllocationLimitExceeded -> Builder +showbAllocationLimitExceeded AllocationLimitExceeded = "allocation limit exceeded" +{-# INLINE showbAllocationLimitExceeded #-} +#endif + +-- | Convert a 'Deadlock' exception to a 'Builder'. +-- +-- /Since: 2/ +showbDeadlock :: Deadlock -> Builder +showbDeadlock Deadlock = "<<deadlock>>" +{-# INLINE showbDeadlock #-} + +-- | Convert a 'NoMethodError' to a 'Builder'. +-- +-- /Since: 2/ +showbNoMethodError :: NoMethodError -> Builder +showbNoMethodError (NoMethodError err) = fromString err +{-# INLINE showbNoMethodError #-} + +-- | Convert a 'PatternMatchFail' to a 'Builder'. +-- +-- /Since: 2/ +showbPatternMatchFail :: PatternMatchFail -> Builder +showbPatternMatchFail (PatternMatchFail err) = fromString err +{-# INLINE showbPatternMatchFail #-} + +-- | Convert a 'RecConError' to a 'Builder'. +-- +-- /Since: 2/ +showbRecConError :: RecConError -> Builder +showbRecConError (RecConError err) = fromString err +{-# INLINE showbRecConError #-} + +-- | Convert a 'RecSelError' to a 'Builder'. +-- +-- /Since: 2/ +showbRecSelError :: RecSelError -> Builder +showbRecSelError (RecSelError err) = fromString err +{-# INLINE showbRecSelError #-} + +-- | Convert a 'RecUpdError' to a 'Builder'. +-- +-- /Since: 2/ +showbRecUpdError :: RecUpdError -> Builder +showbRecUpdError (RecUpdError err) = fromString err +{-# INLINE showbRecUpdError #-} + +-- | Convert an 'ErrorCall' to a 'Builder'. +-- +-- /Since: 2/ +showbErrorCall :: ErrorCall -> Builder +showbErrorCall (ErrorCall err) = fromString err +{-# INLINE showbErrorCall #-} + +-- | Convert a 'MaskingState' to a 'Builder'. +-- +-- /Since: 2/ +showbMaskingState :: MaskingState -> Builder +showbMaskingState = showb +{-# INLINE showbMaskingState #-} + +instance TextShow SomeException where + showbPrec = showbSomeExceptionPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow IOException where + showb = showbIOException + INLINE_INST_FUN(showb) + +instance TextShow ArithException where + showb = showbArithException + INLINE_INST_FUN(showb) + +instance TextShow ArrayException where + showb = showbArrayException + INLINE_INST_FUN(showb) + +instance TextShow AssertionFailed where + showb = showbAssertionFailed + INLINE_INST_FUN(showb) + +#if MIN_VERSION_base(4,7,0) +instance TextShow SomeAsyncException where + showb = showbSomeAsyncException + {-# INLINE showb #-} +#endif + +instance TextShow AsyncException where + showb = showbAsyncException + INLINE_INST_FUN(showb) + +instance TextShow NonTermination where + showb = showbNonTermination + INLINE_INST_FUN(showb) + +instance TextShow NestedAtomically where + showb = showbNestedAtomically + INLINE_INST_FUN(showb) + +instance TextShow BlockedIndefinitelyOnMVar where + showb = showbBlockedIndefinitelyOnMVar + INLINE_INST_FUN(showb) + +instance TextShow BlockedIndefinitelyOnSTM where + showb = showbBlockedIndefinitelyOnSTM + INLINE_INST_FUN(showb) + +#if MIN_VERSION_base(4,8,0) +instance TextShow AllocationLimitExceeded where + showb = showbAllocationLimitExceeded + {-# INLINE showb #-} +#endif + +instance TextShow Deadlock where + showb = showbDeadlock + INLINE_INST_FUN(showb) + +instance TextShow NoMethodError where + showb = showbNoMethodError + INLINE_INST_FUN(showb) + +instance TextShow PatternMatchFail where + showb = showbPatternMatchFail + INLINE_INST_FUN(showb) + +instance TextShow RecConError where + showb = showbRecConError + INLINE_INST_FUN(showb) + +instance TextShow RecSelError where + showb = showbRecSelError + INLINE_INST_FUN(showb) + +instance TextShow RecUpdError where + showb = showbRecUpdError + INLINE_INST_FUN(showb) + +instance TextShow ErrorCall where + showb = showbErrorCall + INLINE_INST_FUN(showb) + +$(deriveTextShow ''MaskingState)
+ src/TextShow/Control/Monad/ST.hs view
@@ -0,0 +1,41 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Control.Monad.ST +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for strict 'ST' values. + +/Since: 2/ +-} +module TextShow.Control.Monad.ST (showbST) where + +import Control.Monad.ST (ST) +import Data.Text.Lazy.Builder (Builder) +import TextShow.Classes (TextShow(showb), TextShow1(..), TextShow2(..)) + +#include "inline.h" + +-- | Convert a strict 'ST' value to a 'Builder'. +-- +-- /Since: 2/ +showbST :: ST s a -> Builder +showbST = showb +{-# INLINE showbST #-} + +instance TextShow (ST s a) where + showb = showbPrecWith undefined 0 + INLINE_INST_FUN(showb) + +instance TextShow1 (ST s) where + showbPrecWith = showbPrecWith2 undefined + INLINE_INST_FUN(showbPrecWith) + +instance TextShow2 ST where + showbPrecWith2 _ _ _ _ = "<<ST action>>" + INLINE_INST_FUN(showbPrecWith2)
+ src/TextShow/Data/Array.hs view
@@ -0,0 +1,81 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Array +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Array' values. + +/Since: 2/ +-} +module TextShow.Data.Array ( + showbArrayPrec + , showbUArrayPrec + , showbIArrayPrec + ) where + +import qualified Data.Array as Array (assocs, bounds) +import Data.Array (Array) +import qualified Data.Array.Base as IArray (assocs, bounds) +import Data.Array.Base (IArray) +import Data.Array.Unboxed (UArray) +import Data.Ix (Ix) +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder) + +import GHC.Show (appPrec) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(showb, showbPrec), showbParen, showbSpace) +import TextShow.Data.List () +import TextShow.Data.Tuple () + +#include "inline.h" + +-- | Convert an 'Array' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbArrayPrec :: (TextShow i, TextShow e, Ix i) => Int -> Array i e -> Builder +showbArrayPrec p a = showbParen (p > appPrec) $ + "array " + <> showb (Array.bounds a) + <> showbSpace + <> showb (Array.assocs a) +{-# INLINE showbArrayPrec #-} + +-- | Convert a 'UArray' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbUArrayPrec :: (IArray UArray e, Ix i, TextShow i, TextShow e) => Int -> UArray i e -> Builder +showbUArrayPrec = showbIArrayPrec +{-# INLINE showbUArrayPrec #-} + +{-# SPECIALIZE + showbIArrayPrec :: (IArray UArray e, Ix i, TextShow i, TextShow e) => + Int -> UArray i e -> Builder + #-} +-- | Convert an 'IArray' instance to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbIArrayPrec :: (IArray a e, Ix i, TextShow i, TextShow e) => Int -> a i e -> Builder +showbIArrayPrec p a = showbParen (p > 9) $ + "array " + <> showb (IArray.bounds a) + <> showbSpace + <> showb (IArray.assocs a) + +instance (TextShow i, TextShow e, Ix i) => TextShow (Array i e) where + showbPrec = showbArrayPrec + INLINE_INST_FUN(showbPrec) + +instance (IArray UArray e, Ix i, TextShow i, TextShow e) => TextShow (UArray i e) where + showbPrec = showbUArrayPrec + INLINE_INST_FUN(showbPrec)
+ src/TextShow/Data/Bool.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Bool +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Bool' values. + +/Since: 2/ +-} +module TextShow.Data.Bool (showbBool) where + +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (showb) +import TextShow.TH.Internal (deriveTextShow) + +-- | Convert a 'Bool' to a 'Builder'. +-- +-- /Since: 2/ +showbBool :: Bool -> Builder +showbBool = showb +{-# INLINE showbBool #-} + +$(deriveTextShow ''Bool)
+ src/TextShow/Data/ByteString.hs view
@@ -0,0 +1,92 @@+{-# LANGUAGE CPP #-} +#if !(MIN_VERSION_bytestring(0,10,0)) +{-# LANGUAGE TemplateHaskell #-} +#endif +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.ByteString +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the @bytestring@ library. + +/Since: 2/ +-} +module TextShow.Data.ByteString ( + showbByteStringStrict + , showbByteStringLazy + , showbByteStringLazyPrec + , showbShortByteString + ) where + +import qualified Data.ByteString as BS +import qualified Data.ByteString.Lazy as BL +import Data.ByteString.Short (ShortByteString) +import Data.Text.Lazy.Builder (Builder) + +import Prelude hiding (Show(show)) + +import TextShow.Classes (TextShow(showb, showbPrec), FromStringShow(..)) + +#if !(MIN_VERSION_bytestring(0,10,0)) +import TextShow.TH.Internal (deriveTextShow) +#endif + +#include "inline.h" + +-- | Convert a strict 'BS.ByteString' to a 'Builder'. +-- +-- /Since: 2/ +showbByteStringStrict :: BS.ByteString -> Builder +showbByteStringStrict = showb . FromStringShow +{-# INLINE showbByteStringStrict #-} + +-- | Convert a lazy 'BL.ByteString' to a 'Builder'. +-- +-- /Since: 2/ +showbByteStringLazy :: BL.ByteString -> Builder +showbByteStringLazy = showbByteStringLazyPrec 0 +{-# INLINE showbByteStringLazy #-} + +-- | Convert a lazy 'BL.ByteString' to a 'Builder' with the given precedence. +-- +-- With @bytestring-0.10.0.0@ or later, this function ignores the precedence +-- argument, since lazy 'BL.ByteString's are printed out identically to 'String's. +-- On earlier versions of @bytestring@, however, lazy 'BL.ByteString's can be printed +-- with parentheses (e.g., @Chunk "example" Empty@ vs. @(Chunk "example" Empty)@) +-- depending on the precedence. +-- +-- /Since: 2/ +showbByteStringLazyPrec :: Int -> BL.ByteString -> Builder +#if MIN_VERSION_bytestring(0,10,0) +showbByteStringLazyPrec _ = showb . FromStringShow +#else +showbByteStringLazyPrec = showbPrec +#endif +{-# INLINE showbByteStringLazyPrec #-} + +-- | Convert a 'ShortByteString' to a 'Builder'. +-- +-- /Since: 2/ +showbShortByteString :: ShortByteString -> Builder +showbShortByteString = showb . FromStringShow +{-# INLINE showbShortByteString #-} + +instance TextShow BS.ByteString where + showb = showbByteStringStrict + INLINE_INST_FUN(showb) + +#if MIN_VERSION_bytestring(0,10,0) +instance TextShow BL.ByteString where + showbPrec = showbByteStringLazyPrec + INLINE_INST_FUN(showbPrec) +#else +$(deriveTextShow ''BL.ByteString) +#endif + +instance TextShow ShortByteString where + showb = showbShortByteString + INLINE_INST_FUN(showb)
+ src/TextShow/Data/Char.hs view
@@ -0,0 +1,109 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Char +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for 'Char' and 'String'. + +/Since: 2/ +-} +module TextShow.Data.Char ( + showbChar + , showbLitChar + , showbString + , showbLitString + , showbGeneralCategory + , asciiTabB + ) where + +import Data.Array (Array, (!), listArray) +import Data.Char (GeneralCategory, isDigit, ord) +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, singleton) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(..)) +import TextShow.Data.Integral (showbIntPrec) +import TextShow.TH.Internal (deriveTextShow) + +#include "inline.h" + +-- | A table of ASCII control characters that needs to be escaped with a backslash. +-- +-- /Since: 2/ +asciiTabB :: Array Int Builder +asciiTabB = listArray (0, 32) ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", + "BS" , "HT" , "LF" , "VT" , "FF" , "CR" , "SO" , "SI" , + "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", + "CAN", "EM" , "SUB", "ESC", "FS" , "GS" , "RS" , "US" , + "SP"] + +-- | Convert a 'Char' to a 'Builder' (surrounded by single quotes). +-- +-- /Since: 2/ +showbChar :: Char -> Builder +showbChar '\'' = "'\\''" +showbChar c = singleton '\'' <> showbLitChar c <> singleton '\'' +{-# INLINE showbChar #-} + +-- | Convert a 'Char' to a 'Builder' (without single quotes). +-- +-- /Since: 2/ +showbLitChar :: Char -> Builder +showbLitChar c | c > '\DEL' = singleton '\\' <> showbIntPrec 0 (ord c) +showbLitChar '\DEL' = "\\DEL" +showbLitChar '\\' = "\\\\" +showbLitChar c | c >= ' ' = singleton c +showbLitChar '\a' = "\\a" +showbLitChar '\b' = "\\b" +showbLitChar '\f' = "\\f" +showbLitChar '\n' = "\\n" +showbLitChar '\r' = "\\r" +showbLitChar '\t' = "\\t" +showbLitChar '\v' = "\\v" +showbLitChar '\SO' = "\\SO" +showbLitChar c = singleton '\\' <> (asciiTabB ! ord c) + +-- | Convert a 'String' to a 'Builder' (surrounded by double quotes). +-- +-- /Since: 2/ +showbString :: String -> Builder +showbString cs = singleton '"' <> showbLitString cs <> singleton '"' +{-# INLINE showbString #-} + +-- | Convert a 'String' to a 'Builder' (without double quotes). +-- +-- /Since: 2/ +showbLitString :: String -> Builder +showbLitString [] = mempty +showbLitString ('\SO':'H':cs) = "\\SO\\&H" <> showbLitString cs +showbLitString ('"':cs) = "\\\"" <> showbLitString cs +showbLitString (c:d:cs) + | c > '\DEL' && isDigit d = singleton '\\' <> showbIntPrec 0 (ord c) <> "\\&" + <> singleton d <> showbLitString cs +showbLitString (c:cs) = showbLitChar c <> showbLitString cs + +-- | Convert a 'GeneralCategory' to a 'Builder'. +-- +-- /Since: 2/ +showbGeneralCategory :: GeneralCategory -> Builder +showbGeneralCategory = showb +{-# INLINE showbGeneralCategory #-} + +instance TextShow Char where + showb = showbChar + INLINE_INST_FUN(showb) + + showbList = showbString + INLINE_INST_FUN(showbList) + +$(deriveTextShow ''GeneralCategory)
+ src/TextShow/Data/Complex.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Ratio +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Ratio' values. + +Due to use of the @DatatypeContexts@ extension, there is no @TextShow1 Complex@ +instance on @base-4.3.0.0@. + +/Since: 2/ +-} +module TextShow.Data.Complex (showbComplexPrec) where + +import Data.Complex (Complex) +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (TextShow(showbPrec)) +import TextShow.Data.Floating () +import TextShow.TH.Internal (makeShowbPrec) +#if MIN_VERSION_base(4,4,0) +import TextShow.TH.Internal (deriveTextShow1) +#endif + +#include "inline.h" + +-- | Convert a 'Complex' value to a 'Builder' with the given precedence. +-- +-- Note that on @base-4.3.0.0@, this function must have a @('TextShow' a, +-- 'RealFloat' a)@ constraint instead of just a @('TextShow' a)@ constraint. +-- +-- /Since: 2/ +#if MIN_VERSION_base(4,4,0) +showbComplexPrec :: TextShow a +#else +showbComplexPrec :: (RealFloat a, TextShow a) +#endif + => Int + -> Complex a + -> Builder +showbComplexPrec = showbPrec +{-# INLINE showbComplexPrec #-} + +instance +#if MIN_VERSION_base(4,4,0) + TextShow a +#else + (RealFloat a, TextShow a) +#endif + => TextShow (Complex a) where + {-# SPECIALIZE instance TextShow (Complex Float) #-} + {-# SPECIALIZE instance TextShow (Complex Double) #-} + showbPrec = $(makeShowbPrec ''Complex) + INLINE_INST_FUN(showbPrec) + +#if MIN_VERSION_base(4,4,0) +$(deriveTextShow1 ''Complex) +#endif
+ src/TextShow/Data/Data.hs view
@@ -0,0 +1,76 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Data +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the @Data.Data@ module. + +/Since: 2/ +-} +module TextShow.Data.Data ( + showbConstr + , showbConstrRepPrec + , showbDataRepPrec + , showbDataTypePrec + , showbFixity + ) where + +import Data.Data (Constr, ConstrRep, DataRep, DataType, Fixity, showConstr) +import Data.Text.Lazy.Builder (Builder, fromString) + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.Data.List () +import TextShow.Data.Ratio () +import TextShow.TH.Internal (deriveTextShow) + +#include "inline.h" + +-- | Convert a 'DataType' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbDataTypePrec :: Int -> DataType -> Builder +showbDataTypePrec = showbPrec +{-# INLINE showbDataTypePrec #-} + +-- | Convert a 'DataRep' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbDataRepPrec :: Int -> DataRep -> Builder +showbDataRepPrec = showbPrec +{-# INLINE showbDataRepPrec #-} + +-- | Convert a 'Constr' to a 'Builder'. +-- +-- /Since: 2/ +showbConstr :: Constr -> Builder +showbConstr = fromString . showConstr +{-# INLINE showbConstr #-} + +-- | Convert a 'Fixity' value to a 'Builder'. +-- +-- /Since: 2/ +showbFixity :: Fixity -> Builder +showbFixity = showb +{-# INLINE showbFixity #-} + +-- | Convert a 'ConstrRep' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbConstrRepPrec :: Int -> ConstrRep -> Builder +showbConstrRepPrec = showbPrec +{-# INLINE showbConstrRepPrec #-} + +$(deriveTextShow ''DataType) +$(deriveTextShow ''DataRep) +$(deriveTextShow ''ConstrRep) +$(deriveTextShow ''Fixity) + +instance TextShow Constr where + showb = showbConstr + INLINE_INST_FUN(showb)
+ src/TextShow/Data/Dynamic.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Dynamic +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Dynamic'. + +/Since: 2/ +-} +module TextShow.Data.Dynamic (showbDynamic) where + +import Data.Dynamic (Dynamic, dynTypeRep) +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder) + +import Prelude () + +import TextShow.Classes (TextShow(showb)) +import TextShow.Data.Typeable (showbTypeRepPrec) + +#include "inline.h" + +-- | Convert a 'Dynamic' value to a 'Builder'. +-- +-- /Since: 2/ +showbDynamic :: Dynamic -> Builder +showbDynamic dyn = "<<" <> showbTypeRepPrec 0 (dynTypeRep dyn) <> ">>" +{-# INLINE showbDynamic #-} + +instance TextShow Dynamic where + showb = showbDynamic + INLINE_INST_FUN(showb)
+ src/TextShow/Data/Either.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Either +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Either' values. + +/Since: 2/ +-} +module TextShow.Data.Either (showbEitherPrecWith2) where + +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (showbPrecWith2) +import TextShow.TH.Internal (deriveTextShow, deriveTextShow1, deriveTextShow2) + +#include "inline.h" + +-- | Convert a 'Either' value to a 'Builder' with the given show functions +-- and precedence. +-- +-- /Since: 2/ +showbEitherPrecWith2 :: (Int -> a -> Builder) -> (Int -> b -> Builder) + -> Int -> Either a b -> Builder +showbEitherPrecWith2 = showbPrecWith2 +{-# INLINE showbEitherPrecWith2 #-} + +$(deriveTextShow ''Either) +$(deriveTextShow1 ''Either) +$(deriveTextShow2 ''Either)
+ src/TextShow/Data/Fixed.hs view
@@ -0,0 +1,93 @@+{-# LANGUAGE CPP #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Fixed +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'Show' function for 'Fixed' values. + +/Since: 2/ +-} +module TextShow.Data.Fixed (showbFixed) where + +import Data.Fixed (HasResolution(..)) +import Data.Text.Lazy.Builder (Builder) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(showb)) + +#if MIN_VERSION_base(4,7,0) +import Data.Fixed (Fixed(..)) +import Data.Int (Int64) +import Data.Monoid.Compat ((<>)) +import Data.Semigroup (timesN) +import Data.Text.Lazy.Builder (singleton) + +import TextShow.Data.Integral () +import TextShow.Utils (lengthB) +#else +import Data.Fixed (Fixed, showFixed) +import Data.Text.Lazy.Builder (fromString) +#endif + +#include "inline.h" + +-- | Convert a 'Fixed' value to a 'Builder', where the first argument indicates +-- whether to chop off trailing zeroes. +-- +-- /Since: 2/ +showbFixed :: HasResolution a => Bool -> Fixed a -> Builder +#if MIN_VERSION_base(4,7,0) +showbFixed chopTrailingZeroes fa@(MkFixed a) | a < 0 + = singleton '-' <> showbFixed chopTrailingZeroes (asTypeOf (MkFixed (negate a)) fa) +showbFixed chopTrailingZeroes fa@(MkFixed a) + = showb i <> withDotB (showbIntegerZeroes chopTrailingZeroes digits fracNum) + where + res = fromInteger $ resolution fa + (i, d) = divMod (fromInteger a) res + digits = ceiling (logBase 10 (fromInteger $ resolution fa) :: Double) + maxnum = 10 ^ digits +# if MIN_VERSION_base(4,8,0) + fracNum = divCeil (d * maxnum) res + divCeil x y = (x + y - 1) `div` y +# else + fracNum = div (d * maxnum) res +# endif +#else +showbFixed chopTrailingZeroes = fromString . showFixed chopTrailingZeroes +{-# INLINE showbFixed #-} +#endif + +#if MIN_VERSION_base(4,7,0) +-- | Only works for positive 'Integer's. +showbIntegerZeroes :: Bool -> Int64 -> Integer -> Builder +showbIntegerZeroes True _ 0 = mempty +showbIntegerZeroes chopTrailingZeroes digits a + = timesN (fromIntegral . max 0 $ digits - lengthB sh) (singleton '0') <> sh' + where + sh, sh' :: Builder + sh = showb a + sh' = if chopTrailingZeroes then chopZeroesB a else sh + +-- | Chops off the trailing zeroes of an 'Integer'. +chopZeroesB :: Integer -> Builder +chopZeroesB 0 = mempty +chopZeroesB a | mod a 10 == 0 = chopZeroesB (div a 10) +chopZeroesB a = showb a + +-- | Prepends a dot to a non-empty 'Builder'. +withDotB :: Builder -> Builder +withDotB b | b == mempty = mempty + | otherwise = singleton '.' <> b +{-# INLINE withDotB #-} +#endif + +instance HasResolution a => TextShow (Fixed a) where + showb = showbFixed False + INLINE_INST_FUN(showb)
+ src/TextShow/Data/Floating.hs view
@@ -0,0 +1,411 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Floating +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for floating-point types. + +/Since: 2/ +-} +module TextShow.Data.Floating ( + showbRealFloatPrec + , showbFloatPrec + , showbDoublePrec + , showbEFloat + , showbFFloat + , showbGFloat + , showbFFloatAlt + , showbGFloatAlt + , showbFPFormat + , FPFormat(..) + , formatRealFloatB + , formatRealFloatAltB + ) where + +import Data.Array.Base (unsafeAt) +import Data.Array.IArray (Array, array) +import Data.Monoid.Compat ((<>)) +import qualified Data.Text as T (replicate) +import Data.Text.Lazy.Builder (Builder, fromString, fromText, singleton) +import Data.Text.Lazy.Builder.Int (decimal) +import Data.Text.Lazy.Builder.RealFloat (FPFormat(..)) + +import TextShow.Classes (TextShow(showb, showbPrec), showbParen) +import TextShow.TH.Internal (deriveTextShow) +import TextShow.Utils (i2d) + +#include "inline.h" + +-- | Convert a 'RealFloat' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbRealFloatPrec :: RealFloat a => Int -> a -> Builder +showbRealFloatPrec p x + | x < 0 || isNegativeZero x = showbParen (p > 6) $ singleton '-' <> showbGFloat Nothing (-x) + | otherwise = showbGFloat Nothing x +{-# INLINE showbRealFloatPrec #-} + +-- | Convert a 'Float' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbFloatPrec :: Int -> Float -> Builder +showbFloatPrec = showbRealFloatPrec +{-# INLINE showbFloatPrec #-} + +-- | Convert a 'Double' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbDoublePrec :: Int -> Double -> Builder +showbDoublePrec = showbRealFloatPrec +{-# INLINE showbDoublePrec #-} + +-- | Show a signed 'RealFloat' value +-- using scientific (exponential) notation (e.g. @2.45e2@, @1.5e-3@). +-- +-- In the call @'showbEFloat' digs val@, if @digs@ is 'Nothing', +-- the value is shown to full precision; if @digs@ is @'Just' d@, +-- then at most @d@ digits after the decimal point are shown. +-- +-- /Since: 2/ +showbEFloat :: RealFloat a => Maybe Int -> a -> Builder +showbEFloat = formatRealFloatB Exponent +{-# INLINE showbEFloat #-} + +-- | Show a signed 'RealFloat' value +-- using standard decimal notation (e.g. @245000@, @0.0015@). +-- +-- In the call @'showbFFloat' digs val@, if @digs@ is 'Nothing', +-- the value is shown to full precision; if @digs@ is @'Just' d@, +-- then at most @d@ digits after the decimal point are shown. +-- +-- /Since: 2/ +showbFFloat :: RealFloat a => Maybe Int -> a -> Builder +showbFFloat = formatRealFloatB Fixed +{-# INLINE showbFFloat #-} + +-- | Show a signed 'RealFloat' value +-- using standard decimal notation for arguments whose absolute value lies +-- between @0.1@ and @9,999,999@, and scientific notation otherwise. +-- +-- In the call @'showbGFloat' digs val@, if @digs@ is 'Nothing', +-- the value is shown to full precision; if @digs@ is @'Just' d@, +-- then at most @d@ digits after the decimal point are shown. +-- +-- /Since: 2/ +showbGFloat :: RealFloat a => Maybe Int -> a -> Builder +showbGFloat = formatRealFloatB Generic +{-# INLINE showbGFloat #-} + +-- | Show a signed 'RealFloat' value +-- using standard decimal notation (e.g. @245000@, @0.0015@). +-- +-- This behaves as 'showFFloat', except that a decimal point +-- is always guaranteed, even if not needed. +-- +-- /Since: 2/ +showbFFloatAlt :: RealFloat a => Maybe Int -> a -> Builder +showbFFloatAlt d = formatRealFloatAltB Fixed d True +{-# INLINE showbFFloatAlt #-} + +-- | Show a signed 'RealFloat' value +-- using standard decimal notation for arguments whose absolute value lies +-- between @0.1@ and @9,999,999@, and scientific notation otherwise. +-- +-- This behaves as 'showFFloat', except that a decimal point +-- is always guaranteed, even if not needed. +-- +-- /Since: 2/ +showbGFloatAlt :: RealFloat a => Maybe Int -> a -> Builder +showbGFloatAlt d = formatRealFloatAltB Generic d True +{-# INLINE showbGFloatAlt #-} + +-- | Convert an 'FPFormat' value to a 'Builder'. +-- +-- /Since: 2/ +showbFPFormat :: FPFormat -> Builder +showbFPFormat = showb +{-# INLINE showbFPFormat #-} + +------------------------------------------------------------------------------- +-- GHC.Float internal functions, adapted for Builders +------------------------------------------------------------------------------- + +-- | Like 'formatRealFloatAltB', except that the decimal is only shown for arguments +-- whose absolute value is between @0.1@ and @9,999,999@. +-- +-- /Since: 2/ +formatRealFloatB :: RealFloat a + => FPFormat -- ^ What notation to use. + -> Maybe Int -- ^ Number of decimal places to render. + -> a + -> Builder +formatRealFloatB fmt decs = formatRealFloatAltB fmt decs False +{-# INLINE formatRealFloatB #-} + +-- | Converts a 'RealFloat' value to a Builder, specifying if a decimal point +-- should always be shown. +-- +-- /Since: 2/ +formatRealFloatAltB :: RealFloat a + => FPFormat -- ^ What notation to use. + -> Maybe Int -- ^ Number of decimal places to render. + -> Bool -- ^ Should a decimal point always be shown? + -> a + -> Builder +{-# SPECIALIZE formatRealFloatAltB :: FPFormat -> Maybe Int -> Bool -> Float -> Builder #-} +{-# SPECIALIZE formatRealFloatAltB :: FPFormat -> Maybe Int -> Bool -> Double -> Builder #-} +formatRealFloatAltB fmt decs alt x + | isNaN x = "NaN" + | isInfinite x = if x < 0 then "-Infinity" else "Infinity" + | x < 0 || isNegativeZero x = singleton '-' <> doFmt fmt (floatToDigits (-x)) + | otherwise = doFmt fmt (floatToDigits x) + where + doFmt format (is, e) = + let ds = map i2d is in + case format of + Generic -> + doFmt (if e < 0 || e > 7 then Exponent else Fixed) + (is,e) + Exponent -> + case decs of + Nothing -> + let show_e' = decimal (e-1) in + case ds of + "0" -> "0.0e0" + [d] -> singleton d <> ".0e" <> show_e' + (d:ds') -> singleton d <> singleton '.' <> fromString ds' <> singleton 'e' <> show_e' + [] -> error "formatRealFloat/doFmt/Exponent: []" + Just dec -> + let dec' = max dec 1 in + case is of + [0] -> "0." <> fromText (T.replicate dec' "0") <> "e0" + _ -> + let + (ei,is') = roundTo (dec'+1) is + (d:ds') = map i2d (if ei > 0 then init is' else is') + in + singleton d <> singleton '.' <> fromString ds' <> singleton 'e' <> decimal (e-1+ei) + Fixed -> + let + mk0 ls = case ls of { "" -> "0" ; _ -> fromString ls} + in + case decs of + Nothing + | e <= 0 -> "0." <> fromText (T.replicate (-e) "0") <> fromString ds + | otherwise -> + let + f 0 str rs = mk0 (reverse str) <> singleton '.' <> mk0 rs + f n str "" = f (n-1) ('0':str) "" + f n str (r:rs) = f (n-1) (r:str) rs + in + f e "" ds + Just dec -> + let dec' = max dec 0 in + if e >= 0 then + let + (ei,is') = roundTo (dec' + e) is + (ls,rs) = splitAt (e+ei) (map i2d is') + in + mk0 ls <> (if null rs && not alt then "" else singleton '.' <> fromString rs) + else + let + (ei,is') = roundTo dec' (replicate (-e) 0 ++ is) + d:ds' = map i2d (if ei > 0 then is' else 0:is') + in + singleton d <> (if null ds' && not alt then "" else singleton '.' <> fromString ds') + +-- Based on "Printing Floating-Point Numbers Quickly and Accurately" +-- by R.G. Burger and R.K. Dybvig in PLDI 96. +-- This version uses a much slower logarithm estimator. It should be improved. + +-- | 'floatToDigits' takes a base and a non-negative 'RealFloat' number, +-- and returns a list of digits and an exponent. +-- In particular, if @x>=0@, and +-- +-- > floatToDigits base x = ([d1,d2,...,dn], e) +-- +-- then +-- +-- (1) @n >= 1@ +-- +-- (2) @x = 0.d1d2...dn * (base**e)@ +-- +-- (3) @0 <= di <= base-1@ +floatToDigits :: (RealFloat a) => a -> ([Int], Int) +{-# SPECIALIZE floatToDigits :: Float -> ([Int], Int) #-} +{-# SPECIALIZE floatToDigits :: Double -> ([Int], Int) #-} +floatToDigits 0 = ([0], 0) +floatToDigits x = + let + (f0, e0) = decodeFloat x + (minExp0, _) = floatRange x + p = floatDigits x + b = floatRadix x + minExp = minExp0 - p -- the real minimum exponent + -- Haskell requires that f be adjusted so denormalized numbers + -- will have an impossibly low exponent. Adjust for this. + (f, e) = + let n = minExp - e0 in + if n > 0 then (f0 `quot` (expt b n), e0+n) else (f0, e0) + (r, s', mUp, mDn) = + if e >= 0 then + let be = expt b e in + if f == expt b (p-1) then + (f*be*b*2, 2*b, be*b, be) -- according to Burger and Dybvig + else + (f*be*2, 2, be, be) + else + if e > minExp && f == expt b (p-1) then + (f*b*2, expt b (-e+1)*2, b, 1) + else + (f*2, expt b (-e)*2, 1, 1) + k :: Int + k = + let + k0 :: Int + k0 = + if b == 2 then + -- logBase 10 2 is very slightly larger than 8651/28738 + -- (about 5.3558e-10), so if log x >= 0, the approximation + -- k1 is too small, hence we add one and need one fixup step less. + -- If log x < 0, the approximation errs rather on the high side. + -- That is usually more than compensated for by ignoring the + -- fractional part of logBase 2 x, but when x is a power of 1/2 + -- or slightly larger and the exponent is a multiple of the + -- denominator of the rational approximation to logBase 10 2, + -- k1 is larger than logBase 10 x. If k1 > 1 + logBase 10 x, + -- we get a leading zero-digit we don't want. + -- With the approximation 3/10, this happened for + -- 0.5^1030, 0.5^1040, ..., 0.5^1070 and values close above. + -- The approximation 8651/28738 guarantees k1 < 1 + logBase 10 x + -- for IEEE-ish floating point types with exponent fields + -- <= 17 bits and mantissae of several thousand bits, earlier + -- convergents to logBase 10 2 would fail for long double. + -- Using quot instead of div is a little faster and requires + -- fewer fixup steps for negative lx. + let lx = p - 1 + e0 + k1 = (lx * 8651) `quot` 28738 + in if lx >= 0 then k1 + 1 else k1 + else + -- f :: Integer, log :: Float -> Float, + -- ceiling :: Float -> Int + ceiling ((log (fromInteger (f+1) :: Float) + + fromIntegral e * log (fromInteger b)) / + log 10) +--WAS: fromInt e * log (fromInteger b)) + + fixup n = + if n >= 0 then + if r + mUp <= expt 10 n * s' then n else fixup (n+1) + else + if expt 10 (-n) * (r + mUp) <= s' then n else fixup (n+1) + in + fixup k0 + + gen ds rn sN mUpN mDnN = + let + (dn, rn') = (rn * 10) `quotRem` sN + mUpN' = mUpN * 10 + mDnN' = mDnN * 10 + in + case (rn' < mDnN', rn' + mUpN' > sN) of + (True, False) -> dn : ds + (False, True) -> dn+1 : ds + (True, True) -> if rn' * 2 < sN then dn : ds else dn+1 : ds + (False, False) -> gen (dn:ds) rn' sN mUpN' mDnN' + + rds = + if k >= 0 then + gen [] r (s' * expt 10 k) mUp mDn + else + let bk = expt 10 (-k) in + gen [] (r * bk) s' (mUp * bk) (mDn * bk) + in + (map fromIntegral (reverse rds), k) + +roundTo :: Int -> [Int] -> (Int,[Int]) +#if MIN_VERSION_base(4,6,0) +roundTo d is = + case f d True is of + x@(0,_) -> x + (1,xs) -> (1, 1:xs) + _ -> error "roundTo: bad Value" + where + b2 = base `quot` 2 + + f n _ [] = (0, replicate n 0) + f 0 e (x:xs) | x == b2 && e && all (== 0) xs = (0, []) -- Round to even when at exactly half the base + | otherwise = (if x >= b2 then 1 else 0, []) + f n _ (i:xs) + | i' == base = (1,0:ds) + | otherwise = (0,i':ds) + where + (c,ds) = f (n-1) (even i) xs + i' = c + i + base = 10 +#else +roundTo d is = + case f d is of + x@(0,_) -> x + (1,xs) -> (1, 1:xs) + _ -> error "roundTo: bad Value" + where + f n [] = (0, replicate n 0) + f 0 (x:_) = (if x >= 5 then 1 else 0, []) + f n (i:xs) + | i' == 10 = (1,0:ds) + | otherwise = (0,i':ds) + where + (c,ds) = f (n-1) xs + i' = c + i +#endif + +-- Exponentiation with a cache for the most common numbers. + +-- | The minimum exponent in the cache. +minExpt :: Int +minExpt = 0 + +-- | The maximum exponent (of 2) in the cache. +maxExpt :: Int +maxExpt = 1100 + +-- | Exponentiate an 'Integer', using a cache if possible. +expt :: Integer -> Int -> Integer +expt base n + | base == 2 && n >= minExpt && n <= maxExpt = expts `unsafeAt` n + | base == 10 && n <= maxExpt10 = expts10 `unsafeAt` n + | otherwise = base^n + +-- | Cached powers of two. +expts :: Array Int Integer +expts = array (minExpt,maxExpt) [(n,2^n) | n <- [minExpt .. maxExpt]] + +-- | The maximum exponent (of 10) in the cache. +maxExpt10 :: Int +maxExpt10 = 324 + +-- | Cached powers of 10. +expts10 :: Array Int Integer +expts10 = array (minExpt,maxExpt10) [(n,10^n) | n <- [minExpt .. maxExpt10]] + +------------------------------------------------------------------------------- +-- TextShow instances +------------------------------------------------------------------------------- + +instance TextShow Float where + showbPrec = showbFloatPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow Double where + showbPrec = showbDoublePrec + INLINE_INST_FUN(showbPrec) + +$(deriveTextShow ''FPFormat)
+ src/TextShow/Data/Functor/Identity.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Functor.Identity +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Identity' values. + +/Since: 2/ +-} +module TextShow.Data.Functor.Identity (showbIdentityPrecWith) where + +import Data.Functor.Identity (Identity(..)) +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (TextShow(showbPrec), TextShow1(..), + showbPrec1, showbUnaryWith) + +#include "inline.h" + +-- | Convert an 'Identity' value to a 'Builder' with the given show function +-- and precedence. +-- +-- /Since: 2/ +showbIdentityPrecWith :: (Int -> a -> Builder) -> Int -> Identity a -> Builder +-- This would be equivalent to the derived instance of 'Identity' if the +-- 'runIdentity' field were removed. +showbIdentityPrecWith sp p (Identity x) = showbUnaryWith sp "Identity" p x +{-# INLINE showbIdentityPrecWith #-} + +instance TextShow a => TextShow (Identity a) where + showbPrec = showbPrec1 + {-# INLINE showbPrec #-} + +instance TextShow1 Identity where + showbPrecWith = showbIdentityPrecWith + INLINE_INST_FUN(showbPrecWith)
+ src/TextShow/Data/Integral.hs view
@@ -0,0 +1,241 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Integral +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for integral types. + +/Since: 2/ +-} +module TextShow.Data.Integral ( + showbIntPrec + , showbInt8Prec + , showbInt16Prec + , showbInt32Prec + , showbInt64Prec + , showbIntegerPrec + , showbIntegralPrec + , showbIntAtBase + , showbBin + , showbHex + , showbOct + , showbWord + , showbWord8 + , showbWord16 + , showbWord32 + , showbWord64 + ) where + +import Data.Char (intToDigit) +import Data.Int (Int8, Int16, Int32, Int64) +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, singleton) +import Data.Text.Lazy.Builder.Int (decimal) +import Data.Word (Word8, Word16, Word32, Word64) + +import GHC.Exts (Int(I#)) +#if __GLASGOW_HASKELL__ >= 708 +import GHC.Exts (isTrue#) +import GHC.Prim (Int#) +#endif +import GHC.Prim ((<#), (>#)) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.Utils (toString) + +#include "inline.h" + +-- | Convert an 'Int' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbIntPrec :: Int -> Int -> Builder +showbIntPrec (I# p) n'@(I# n) + | isTrue (n <# 0#) && isTrue (p ># 6#) = singleton '(' <> decimal n' <> singleton ')' + | otherwise = decimal n' + where +#if __GLASGOW_HASKELL__ >= 708 + isTrue :: Int# -> Bool + isTrue b = isTrue# b +#else + isTrue :: Bool -> Bool + isTrue = id +#endif + +-- | Convert an 'Int8' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbInt8Prec :: Int -> Int8 -> Builder +showbInt8Prec p = showbIntPrec p . fromIntegral +{-# INLINE showbInt8Prec #-} + +-- | Convert an 'Int16' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbInt16Prec :: Int -> Int16 -> Builder +showbInt16Prec p = showbIntPrec p . fromIntegral +{-# INLINE showbInt16Prec #-} + +-- | Convert an 'Int32' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbInt32Prec :: Int -> Int32 -> Builder +showbInt32Prec p = showbIntPrec p . fromIntegral +{-# INLINE showbInt32Prec #-} + +-- | Convert an 'Int64' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbInt64Prec :: Int -> Int64 -> Builder +#if WORD_SIZE_IN_BITS < 64 +showbInt64Prec p = showbIntegerPrec p . toInteger +#else +showbInt64Prec p = showbIntPrec p . fromIntegral +#endif +{-# INLINE showbInt64Prec #-} + +-- | Convert an 'Integer' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbIntegerPrec :: Int -> Integer -> Builder +showbIntegerPrec p n + | p > 6 && n < 0 = singleton '(' <> decimal n <> singleton ')' + | otherwise = decimal n +{-# INLINE showbIntegerPrec #-} + +-- | Convert an 'Integral' type to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbIntegralPrec :: Integral a => Int -> a -> Builder +showbIntegralPrec p = showbIntegerPrec p . toInteger +{-# INLINE showbIntegralPrec #-} + +-- | Shows a /non-negative/ 'Integral' number using the base specified by the +-- first argument, and the character representation specified by the second. +-- +-- /Since: 2/ +showbIntAtBase :: (Integral a, TextShow a) => a -> (Int -> Char) -> a -> Builder +showbIntAtBase base toChr n0 + | base <= 1 = error . toString $ "TextShow.Int.showbIntAtBase: applied to unsupported base" <> showb base + | n0 < 0 = error . toString $ "TextShow.Int.showbIntAtBase: applied to negative number " <> showb n0 + | otherwise = showbIt (quotRem n0 base) mempty + where + showbIt (n, d) b = seq c $ -- stricter than necessary + case n of + 0 -> b' + _ -> showbIt (quotRem n base) b' + where + c :: Char + c = toChr $ fromIntegral d + + b' :: Builder + b' = singleton c <> b + +-- | Show /non-negative/ 'Integral' numbers in base 2. +-- +-- /Since: 2/ +showbBin :: (Integral a, TextShow a) => a -> Builder +showbBin = showbIntAtBase 2 intToDigit +{-# INLINE showbBin #-} + +-- | Show /non-negative/ 'Integral' numbers in base 16. +-- +-- /Since: 2/ +showbHex :: (Integral a, TextShow a) => a -> Builder +showbHex = showbIntAtBase 16 intToDigit +{-# INLINE showbHex #-} + +-- | Show /non-negative/ 'Integral' numbers in base 8. +-- +-- /Since: 2/ +showbOct :: (Integral a, TextShow a) => a -> Builder +showbOct = showbIntAtBase 8 intToDigit +{-# INLINE showbOct #-} + +-- | Convert a 'Word' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbWord :: Word -> Builder +showbWord = decimal +{-# INLINE showbWord #-} + +-- | Convert a 'Word8' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbWord8 :: Word8 -> Builder +showbWord8 = decimal +{-# INLINE showbWord8 #-} + +-- | Convert a 'Word16' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbWord16 :: Word16 -> Builder +showbWord16 = decimal +{-# INLINE showbWord16 #-} + +-- | Convert a 'Word32' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbWord32 :: Word32 -> Builder +showbWord32 = decimal +{-# INLINE showbWord32 #-} + +-- | Convert a 'Word64' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbWord64 :: Word64 -> Builder +showbWord64 = decimal +{-# INLINE showbWord64 #-} + +instance TextShow Int where + showbPrec = showbIntPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow Int8 where + showbPrec = showbInt8Prec + INLINE_INST_FUN(showbPrec) + +instance TextShow Int16 where + showbPrec = showbInt16Prec + INLINE_INST_FUN(showbPrec) + +instance TextShow Int32 where + showbPrec = showbInt32Prec + INLINE_INST_FUN(showbPrec) + +instance TextShow Int64 where + showbPrec = showbInt64Prec + INLINE_INST_FUN(showbPrec) + +instance TextShow Integer where + showbPrec = showbIntegerPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow Word where + showb = showbWord + INLINE_INST_FUN(showb) + +instance TextShow Word8 where + showb = showbWord8 + INLINE_INST_FUN(showb) + +instance TextShow Word16 where + showb = showbWord16 + INLINE_INST_FUN(showb) + +instance TextShow Word32 where + showb = showbWord32 + INLINE_INST_FUN(showb) + +instance TextShow Word64 where + showb = showbWord64 + INLINE_INST_FUN(showb)
+ src/TextShow/Data/List.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE CPP #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.List +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Exports 'showbListWith'. +-} +module TextShow.Data.List (showbListWith) where + +import TextShow.Classes (TextShow(showb, showbList), TextShow1(..), showbListWith) +import TextShow.Data.Char () +import TextShow.Data.Integral () + +#include "inline.h" + +instance TextShow a => TextShow [a] where + {-# SPECIALIZE instance TextShow [String] #-} + {-# SPECIALIZE instance TextShow String #-} + {-# SPECIALIZE instance TextShow [Int] #-} + showb = showbList + INLINE_INST_FUN(showb) + +instance TextShow1 [] where + showbPrecWith sp _ = showbListWith (sp 0) + INLINE_INST_FUN(showbPrecWith)
+ src/TextShow/Data/Maybe.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Maybe +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Maybe' values. + +/Since: 2/ +-} +module TextShow.Data.Maybe (showbMaybePrecWith) where + +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (showbPrecWith) +import TextShow.TH.Internal (deriveTextShow, deriveTextShow1) + +#include "inline.h" + +-- | Convert a 'Maybe' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbMaybePrecWith :: (Int -> a -> Builder) -> Int -> Maybe a -> Builder +showbMaybePrecWith = showbPrecWith +{-# INLINE showbMaybePrecWith #-} + +$(deriveTextShow ''Maybe) +$(deriveTextShow1 ''Maybe)
+ src/TextShow/Data/Monoid.hs view
@@ -0,0 +1,134 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +#if MIN_VERSION_base(4,8,0) +{-# LANGUAGE FlexibleContexts #-} +#endif +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Monoid +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'Show' functions for 'Monoid'-related newtypes. + +/Since: 2/ +-} +module TextShow.Data.Monoid ( + showbAllPrec + , showbAnyPrec + , showbDualPrecWith + , showbFirstPrecWith + , showbLastPrecWith + , showbProductPrecWith + , showbSumPrecWith +#if MIN_VERSION_base(4,8,0) + , showbAltPrec + , showbAltPrecWith +#endif + ) where + +import Data.Monoid.Compat (All, Any, Dual, First, Last, Product, Sum) +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (TextShow(showbPrec), showbPrecWith) +import TextShow.Data.Bool () +import TextShow.Data.Maybe () +import TextShow.TH.Internal (deriveTextShow, deriveTextShow1) + +#if MIN_VERSION_base(4,8,0) +import Data.Monoid (Alt) +import TextShow.Classes (TextShow1) +import TextShow.TH.Internal (makeShowbPrec) +#endif + +#include "inline.h" + +-- | Convert an 'All' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbAllPrec :: Int -> All -> Builder +showbAllPrec = showbPrec +{-# INLINE showbAllPrec #-} + +-- | Convert an 'Any' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbAnyPrec :: Int -> Any -> Builder +showbAnyPrec = showbPrec +{-# INLINE showbAnyPrec #-} + +-- | Convert a 'Dual' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbDualPrecWith :: (Int -> a -> Builder) -> Int -> Dual a -> Builder +showbDualPrecWith = showbPrecWith +{-# INLINE showbDualPrecWith #-} + +-- | Convert a 'First' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbFirstPrecWith :: (Int -> a -> Builder) -> Int -> First a -> Builder +showbFirstPrecWith = showbPrecWith +{-# INLINE showbFirstPrecWith #-} + +-- | Convert a 'Last' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbLastPrecWith :: (Int -> a -> Builder) -> Int -> Last a -> Builder +showbLastPrecWith = showbPrecWith +{-# INLINE showbLastPrecWith #-} + +-- | Convert a 'Product' value to a 'Builder' with the given show function +-- and precedence. +-- +-- /Since: 2/ +showbProductPrecWith :: (Int -> a -> Builder) -> Int -> Product a -> Builder +showbProductPrecWith = showbPrecWith +{-# INLINE showbProductPrecWith #-} + +-- | Convert a 'Sum' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbSumPrecWith :: (Int -> a -> Builder) -> Int -> Sum a -> Builder +showbSumPrecWith = showbPrecWith +{-# INLINE showbSumPrecWith #-} + +#if MIN_VERSION_base(4,8,0) +-- | Convert an 'Alt' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbAltPrec :: TextShow (f a) => Int -> Alt f a -> Builder +showbAltPrec = showbPrec +{-# INLINE showbAltPrec #-} + +-- | Convert an 'Alt' value to a 'Builder' with the given show function and precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbAltPrecWith :: TextShow1 f => (Int -> a -> Builder) -> Int -> Alt f a -> Builder +showbAltPrecWith = showbPrecWith +#endif + +$(deriveTextShow ''All) +$(deriveTextShow ''Any) +$(deriveTextShow ''Dual) +$(deriveTextShow1 ''Dual) +$(deriveTextShow ''First) +$(deriveTextShow1 ''First) +$(deriveTextShow ''Last) +$(deriveTextShow1 ''Last) +$(deriveTextShow ''Product) +$(deriveTextShow1 ''Product) +$(deriveTextShow ''Sum) +$(deriveTextShow1 ''Sum) + +#if MIN_VERSION_base(4,8,0) +instance TextShow (f a) => TextShow (Alt f a) where + showbPrec = $(makeShowbPrec ''Alt) + +$(deriveTextShow1 ''Alt) +#endif
+ src/TextShow/Data/OldTypeable.hs view
@@ -0,0 +1,76 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,7,0) && !(MIN_VERSION_base(4,8,0)) +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-warnings-deprecations #-} +#endif +{-| +Module: TextShow.Data.OldTypeable +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the @OldTypeable@ module. +This module only exports functions if using @base-4.7@. + +/Since: 2/ +-} +module TextShow.Data.OldTypeable ( +#if !(MIN_VERSION_base(4,7,0)) || MIN_VERSION_base(4,8,0) + ) where +#else + showbTyCon + , showbTypeRepPrec + ) where + +import Data.Monoid.Compat ((<>)) +import Data.OldTypeable.Internal (TyCon(TyCon, tyConName), TypeRep(..), + funTc, listTc) +import Data.Text.Lazy.Builder (Builder, fromString, singleton) + +import TextShow.Classes (TextShow(showb, showbPrec), showbParen, showbSpace) +import TextShow.Data.Typeable.Utils (showbArgs, showbTuple) +import TextShow.Utils (isTupleString) + +-- | Convert a 'TyCon' to a 'Builder'. +-- This function is only available with @base-4.7@. +-- +-- /Since: 2/ +showbTyCon :: TyCon -> Builder +showbTyCon = fromString . tyConName +{-# INLINE showbTyCon #-} + +-- | Convert a 'TypeRep' to a 'Builder' with the given precedence. +-- This function is only available with @base-4.7@. +-- +-- /Since: 2/ +showbTypeRepPrec :: Int -> TypeRep -> Builder +showbTypeRepPrec p (TypeRep _ tycon tys) = + case tys of + [] -> showbTyCon tycon + [x] | tycon == listTc -> singleton '[' <> showb x <> singleton ']' + [a,r] | tycon == funTc -> showbParen (p > 8) $ + showbPrec 9 a + <> " -> " + <> showbPrec 8 r + xs | isTupleTyCon tycon -> showbTuple xs + | otherwise -> showbParen (p > 9) $ + showbPrec p tycon + <> showbSpace + <> showbArgs showbSpace tys + +-- | Does the 'TyCon' represent a tuple type constructor? +isTupleTyCon :: TyCon -> Bool +isTupleTyCon (TyCon _ _ _ str) = isTupleString str +{-# INLINE isTupleTyCon #-} + +instance TextShow TyCon where + showb = showbTyCon + {-# INLINE showb #-} + +instance TextShow TypeRep where + showbPrec = showbTypeRepPrec + {-# INLINE showbPrec #-} +#endif
+ src/TextShow/Data/Ord.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Ord +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for 'Ordering' and 'Down'. + +/Since: 2/ +-} +module TextShow.Data.Ord ( + showbOrdering +#if MIN_VERSION_base(4,6,0) + , showbDownPrecWith +#endif + ) where + +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (showb) +import TextShow.TH.Internal (deriveTextShow) + +#if MIN_VERSION_base(4,6,0) +import Data.Ord (Down) + +import TextShow.Classes (showbPrecWith) +import TextShow.TH.Internal (deriveTextShow1) +#endif + +#include "inline.h" + +-- | Convert a 'Ordering' to a 'Builder'. +-- +-- /Since: 2/ +showbOrdering :: Ordering -> Builder +showbOrdering = showb +{-# INLINE showbOrdering #-} + +#if MIN_VERSION_base(4,6,0) +-- | Convert a 'Down' value to a 'Builder' with the given show function and precedence. +-- This function is only available with @base-4.6.0.0@ or later. +-- +-- /Since: 2/ +showbDownPrecWith :: (Int -> a -> Builder) -> Int -> Down a -> Builder +showbDownPrecWith = showbPrecWith +{-# INLINE showbDownPrecWith #-} +#endif + +$(deriveTextShow ''Ordering) + +#if MIN_VERSION_base(4,6,0) +$(deriveTextShow ''Down) +$(deriveTextShow1 ''Down) +#endif
+ src/TextShow/Data/Proxy.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Proxy +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Proxy' values. + +/Since: 2/ +-} +module TextShow.Data.Proxy (showbProxy) where + +import Data.Proxy (Proxy(..)) +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.TH.Internal (deriveTextShow1, makeShowbPrec) + +#include "inline.h" + +-- | Convert a 'Proxy' type to a 'Builder'. +-- +-- /Since: 2/ +showbProxy :: Proxy s -> Builder +showbProxy = showb +{-# INLINE showbProxy #-} + +instance TextShow (Proxy s) where + showbPrec = $(makeShowbPrec ''Proxy) + INLINE_INST_FUN(showbPrec) + +$(deriveTextShow1 ''Proxy)
+ src/TextShow/Data/Ratio.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Ratio +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Ratio' values. + +/Since: 2/ +-} +module TextShow.Data.Ratio (showbRatioPrec) where + +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder) + +import GHC.Real (Ratio(..), ratioPrec, ratioPrec1) + +import TextShow.Classes (TextShow(showbPrec), showbParen) +#if MIN_VERSION_base(4,4,0) +import TextShow.Classes (TextShow1(..)) +#endif +import TextShow.Data.Integral () + +#include "inline.h" + +-- | Convert a 'Ratio' to a 'Builder' with the given precedence. +-- +-- Note that on @base-4.3.0.0@, this function must have a @('Show' a, 'Integral' a)@ +-- constraint instead of just a @('Show' a)@ constraint. +-- +-- /Since: 2/ +showbRatioPrec :: +#if MIN_VERSION_base(4,4,0) + TextShow a +#else + (TextShow a, Integral a) +#endif + => Int -> Ratio a -> Builder +showbRatioPrec p (numer :% denom) = showbParen (p > ratioPrec) $ + showbPrec ratioPrec1 numer + <> " % " + <> showbPrec ratioPrec1 denom +{-# INLINE showbRatioPrec #-} + +instance +#if MIN_VERSION_base(4,4,0) + TextShow a +#else + (TextShow a, Integral a) +#endif + => TextShow (Ratio a) where + {-# SPECIALIZE instance TextShow Rational #-} + showbPrec = showbRatioPrec + INLINE_INST_FUN(showbPrec) + +#if MIN_VERSION_base(4,4,0) +instance TextShow1 Ratio where + showbPrecWith sp p (numer :% denom) = showbParen (p > ratioPrec) $ + sp ratioPrec1 numer + <> " % " + <> sp ratioPrec1 denom + INLINE_INST_FUN(showbPrecWith) +#endif
+ src/TextShow/Data/Text.hs view
@@ -0,0 +1,155 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +#if MIN_VERSION_text(0,9,0) +{-# LANGUAGE TemplateHaskell #-} +#endif +{-# OPTIONS_GHC -fno-warn-deprecations #-} -- TODO: Remove this later +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Text +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for 'Text' types. + +/Since: 2/ +-} +module TextShow.Data.Text ( + showbText + , showbTextLazy + , showbBuilder + , showbI16Prec + , showbUnicodeException +#if MIN_VERSION_text(1,0,0) + , showbDecodingPrec +#endif +#if MIN_VERSION_text(1,1,0) + , showbSizePrec +#endif + ) where + +import Data.Monoid.Compat ((<>)) +import qualified Data.Text as TS +import Data.Text.Encoding.Error (UnicodeException(..)) +import Data.Text.Foreign (I16) +import qualified Data.Text.Lazy as TL +import Data.Text.Lazy.Builder (Builder, fromString, toLazyText) + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.Data.Char (showbString) +import TextShow.Data.Integral (showbHex) +import TextShow.TH.Internal (deriveTextShow) + +#if MIN_VERSION_text(1,0,0) +import Data.Text.Encoding (Decoding(..)) +import Data.Text.Lazy.Builder (singleton) +import GHC.Show (appPrec) +import TextShow.Classes (showbParen) +import TextShow.Data.ByteString (showbByteStringStrict) +#endif + +#if MIN_VERSION_text(1,1,0) +import Data.Text.Internal.Fusion.Size (Size) +#endif + +#include "inline.h" + +-- | Convert a strict 'TS.Text' to a 'Builder'. +-- 'showbText' should not be confused with @fromText@, as 'showbText' escapes +-- certain characters (such as double quotes). +-- +-- /Since: 2/ +showbText :: TS.Text -> Builder +showbText = showbString . TS.unpack +{-# INLINE showbText #-} + +-- | Convert a lazy 'TL.Text' to a 'Builder'. +-- 'showbTextLazy' should not be confused with @fromTextLazy@, as 'showbTextLazy' +-- escapes certain characters (such as double quotes). +-- +-- /Since: 2/ +showbTextLazy :: TL.Text -> Builder +showbTextLazy = showbString . TL.unpack +{-# INLINE showbTextLazy #-} + +-- | Show a 'Builder' as if it were a 'String' (i.e., escape certain characters, +-- such as double quotes). +-- +-- /Since: 2/ +showbBuilder :: Builder -> Builder +showbBuilder = showbTextLazy . toLazyText +{-# INLINE showbBuilder #-} + +-- | Convert an 'I16' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbI16Prec :: Int -> I16 -> Builder +showbI16Prec = showbPrec +{-# INLINE showbI16Prec #-} + +-- | Convert a 'UnicodeException' to a 'Builder'. +-- +-- /Since: 2/ +showbUnicodeException :: UnicodeException -> Builder +showbUnicodeException (DecodeError desc (Just w)) + = "Cannot decode byte '\\x" <> showbHex w <> "': " <> fromString desc +showbUnicodeException (DecodeError desc Nothing) + = "Cannot decode input: " <> fromString desc +showbUnicodeException (EncodeError desc (Just c)) + = "Cannot encode character '\\x" <> showbHex (fromEnum c) <> "': " <> fromString desc +showbUnicodeException (EncodeError desc Nothing) + = "Cannot encode input: " <> fromString desc + +#if MIN_VERSION_text(1,0,0) +-- | Convert a 'Decoding' value to a 'Builder' with the given precedence. +-- This function is only available with @text-1.0.0.0@ or later. +-- +-- /Since: 2/ +showbDecodingPrec :: Int -> Decoding -> Builder +showbDecodingPrec p (Some t bs _) = showbParen (p > appPrec) $ + fromString "Some " <> showbText t <> + singleton ' ' <> showbByteStringStrict bs <> + fromString " _" +{-# INLINE showbDecodingPrec #-} +#endif + +#if MIN_VERSION_text(1,1,0) +-- | Convert a 'Size' value to a 'Builder' with the given precedence. +-- This function is only available with @text-1.1.0.0@ or later. +-- +-- /Since: 2/ +showbSizePrec :: Int -> Size -> Builder +showbSizePrec = showbPrec +{-# INLINE showbSizePrec #-} +#endif + +instance TextShow TS.Text where + showb = showbText + INLINE_INST_FUN(showb) + +instance TextShow TL.Text where + showb = showbTextLazy + INLINE_INST_FUN(showb) + +instance TextShow Builder where + showb = showbBuilder + INLINE_INST_FUN(showb) + +$(deriveTextShow ''I16) + +instance TextShow UnicodeException where + showb = showbUnicodeException + INLINE_INST_FUN(showb) + +#if MIN_VERSION_text(1,0,0) +instance TextShow Decoding where + showbPrec = showbDecodingPrec + INLINE_INST_FUN(showbPrec) +#endif + +#if MIN_VERSION_text(1,1,0) +$(deriveTextShow ''Size) +#endif
+ src/TextShow/Data/Tuple.hs view
@@ -0,0 +1,229 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Tuple +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for tuple types. + +/Since: 2/ +-} +module TextShow.Data.Tuple ( + showbUnit + , showb2TupleWith2 + , showb3TupleWith2 + , showb4TupleWith2 + , showb5TupleWith2 + , showb6TupleWith2 + , showb7TupleWith2 + , showb8TupleWith2 + , showb9TupleWith2 + , showb10TupleWith2 + , showb11TupleWith2 + , showb12TupleWith2 + , showb13TupleWith2 + , showb14TupleWith2 + , showb15TupleWith2 + ) where + +import Data.Text.Lazy.Builder (Builder) + +import TextShow.Classes (TextShow(showb), TextShow2(..)) +import TextShow.TH.Internal (deriveTextShow, deriveTextShow1, deriveTextShow2) + +#include "inline.h" + +-- | Converts @()@ into a 'Builder'. +-- +-- /Since: 2/ +showbUnit :: () -> Builder +-- showbUnit () = "()" +showbUnit = showb +{-# INLINE showbUnit #-} + +-- | Converts a 2-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb2TupleWith2 :: (a -> Builder) -> (b -> Builder) + -> (a, b) -> Builder +showb2TupleWith2 = showbWith2 +{-# INLINE showb2TupleWith2 #-} + +-- | Converts a 3-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb3TupleWith2 :: TextShow a + => (b -> Builder) -> (c -> Builder) + -> (a, b, c) -> Builder +showb3TupleWith2 = showbWith2 +{-# INLINE showb3TupleWith2 #-} + +-- | Converts a 4-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb4TupleWith2 :: (TextShow a, TextShow b) + => (c -> Builder) -> (d -> Builder) + -> (a, b, c, d) -> Builder +showb4TupleWith2 = showbWith2 +{-# INLINE showb4TupleWith2 #-} + +-- | Converts a 5-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb5TupleWith2 :: (TextShow a, TextShow b, TextShow c) + => (d -> Builder) -> (e -> Builder) + -> (a, b, c, d, e) -> Builder +showb5TupleWith2 = showbWith2 +{-# INLINE showb5TupleWith2 #-} + +-- | Converts a 6-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb6TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d) + => (e -> Builder) -> (f -> Builder) + -> (a, b, c, d, e, f) -> Builder +showb6TupleWith2 = showbWith2 +{-# INLINE showb6TupleWith2 #-} + +-- | Converts a 7-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb7TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e) + => (f -> Builder) -> (g -> Builder) + -> (a, b, c, d, e, f, g) -> Builder +showb7TupleWith2 = showbWith2 +{-# INLINE showb7TupleWith2 #-} + +-- | Converts an 8-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb8TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f) + => (g -> Builder) -> (h -> Builder) + -> (a, b, c, d, e, f, g, h) -> Builder +showb8TupleWith2 = showbWith2 +{-# INLINE showb8TupleWith2 #-} + +-- | Converts a 9-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb9TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g) + => (h -> Builder) -> (i -> Builder) + -> (a, b, c, d, e, f, g, h, i) -> Builder +showb9TupleWith2 = showbWith2 +{-# INLINE showb9TupleWith2 #-} + +-- | Converts a 10-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb10TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, TextShow h) + => (i -> Builder) -> (j -> Builder) + -> (a, b, c, d, e, f, g, h, i, j) -> Builder +showb10TupleWith2 = showbWith2 +{-# INLINE showb10TupleWith2 #-} + +-- | Converts an 11-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb11TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, + TextShow f, TextShow g, TextShow h, TextShow i) + => (j -> Builder) -> (k -> Builder) + -> (a, b, c, d, e, f, g, h, i, j, k) -> Builder +showb11TupleWith2 = showbWith2 +{-# INLINE showb11TupleWith2 #-} + +-- | Converts a 12-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb12TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, + TextShow f, TextShow g, TextShow h, TextShow i, TextShow j) + => (k -> Builder) -> (l -> Builder) + -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Builder +showb12TupleWith2 = showbWith2 +{-# INLINE showb12TupleWith2 #-} + +-- | Converts a 13-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb13TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, + TextShow g, TextShow h, TextShow i, TextShow j, TextShow k) + => (l -> Builder) -> (m -> Builder) + -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Builder +showb13TupleWith2 = showbWith2 +{-# INLINE showb13TupleWith2 #-} + +-- | Converts a 14-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb14TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, + TextShow g, TextShow h, TextShow i, TextShow j, TextShow k, TextShow l) + => (m -> Builder) -> (n -> Builder) + -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Builder +showb14TupleWith2 = showbWith2 +{-# INLINE showb14TupleWith2 #-} + +-- | Converts a 15-tuple into a 'Builder' with the given show functions. +-- +-- /Since: 2/ +showb15TupleWith2 :: (TextShow a, TextShow b, TextShow c, TextShow d, TextShow e, TextShow f, TextShow g, + TextShow h, TextShow i, TextShow j, TextShow k, TextShow l, TextShow m) + => (n -> Builder) -> (o -> Builder) + -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Builder +showb15TupleWith2 = showbWith2 +{-# INLINE showb15TupleWith2 #-} + +-- | Like 'showbPrecWith2', except precedence-agnostic. +showbWith2 :: TextShow2 f => (a -> Builder) -> (b -> Builder) -> f a b -> Builder +showbWith2 sp1 sp2 = showbPrecWith2 (const sp1) (const sp2) 0 +{-# INLINE showbWith2 #-} + +-- The Great Pyramids of Template Haskell +$(deriveTextShow ''()) +$(deriveTextShow ''(,)) +$(deriveTextShow ''(,,)) +$(deriveTextShow ''(,,,)) +$(deriveTextShow ''(,,,,)) +$(deriveTextShow ''(,,,,,)) +$(deriveTextShow ''(,,,,,,)) +$(deriveTextShow ''(,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,,,,,,)) +$(deriveTextShow ''(,,,,,,,,,,,,,,)) + +$(deriveTextShow1 ''(,)) +$(deriveTextShow1 ''(,,)) +$(deriveTextShow1 ''(,,,)) +$(deriveTextShow1 ''(,,,,)) +$(deriveTextShow1 ''(,,,,,)) +$(deriveTextShow1 ''(,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,,,,,,)) +$(deriveTextShow1 ''(,,,,,,,,,,,,,,)) + +$(deriveTextShow2 ''(,)) +$(deriveTextShow2 ''(,,)) +$(deriveTextShow2 ''(,,,)) +$(deriveTextShow2 ''(,,,,)) +$(deriveTextShow2 ''(,,,,,)) +$(deriveTextShow2 ''(,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,,,,,,)) +$(deriveTextShow2 ''(,,,,,,,,,,,,,,))
+ src/TextShow/Data/Type/Coercion.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,7,0) +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.Data.Type.Coercion +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for representational equality. +This module only exports functions if using @base-4.7.0.0@ or later. + +/Since: 2/ +-} +module TextShow.Data.Type.Coercion ( +#if !(MIN_VERSION_base(4,7,0)) + ) where +#else + showbCoercion + ) where + +import Data.Text.Lazy.Builder (Builder) +import Data.Type.Coercion (Coercion(..)) + +import TextShow.Classes (TextShow(showb, showbPrec), TextShow1(..)) +import TextShow.TH.Internal (deriveTextShow2, makeShowbPrec, makeShowbPrecWith) + +-- | Convert a representational equality value to a 'Builder'. +-- This function is only available with @base-4.7.0.0@ or later. +-- +-- /Since: 2/ +showbCoercion :: Coercion a b -> Builder +showbCoercion = showb +{-# INLINE showbCoercion #-} + +instance TextShow (Coercion a b) where + showbPrec = $(makeShowbPrec ''Coercion) + {-# INLINE showb #-} + +instance TextShow1 (Coercion a) where + showbPrecWith = $(makeShowbPrecWith ''Coercion) + {-# INLINE showbPrecWith #-} + +$(deriveTextShow2 ''Coercion) +#endif
+ src/TextShow/Data/Type/Equality.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,7,0) +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.Data.Type.Equality +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for propositional equality. +This module only exports functions if using @base-4.7.0.0@ or later. + +/Since: 2/ +-} +module TextShow.Data.Type.Equality ( +#if !(MIN_VERSION_base(4,7,0)) + ) where +#else + showbPropEquality + ) where + +import Data.Text.Lazy.Builder (Builder) +import Data.Type.Equality ((:~:)(..)) + +import TextShow.Classes (TextShow(showb, showbPrec), TextShow1(..)) +import TextShow.TH.Internal (deriveTextShow2, makeShowbPrec, makeShowbPrecWith) + +-- | Convert a propositional equality value to a 'Builder'. +-- This function is only available with @base-4.7.0.0@ or later. +-- +-- /Since: 2/ +showbPropEquality :: (a :~: b) -> Builder +showbPropEquality = showb +{-# INLINE showbPropEquality #-} + +instance TextShow (a :~: b) where + showbPrec = $(makeShowbPrec ''(:~:)) + {-# INLINE showbPrec #-} + +instance TextShow1 ((:~:) a) where + showbPrecWith = $(makeShowbPrecWith ''(:~:)) + {-# INLINE showbPrecWith #-} + +$(deriveTextShow2 ''(:~:)) +#endif
+ src/TextShow/Data/Typeable.hs view
@@ -0,0 +1,102 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Typeable +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the @Typeable@ module. + +/Since: 2/ +-} +module TextShow.Data.Typeable (showbTyCon, showbTypeRepPrec) where + +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, fromString, singleton) +import Data.Typeable (TypeRep, typeRepArgs, typeRepTyCon) +#if MIN_VERSION_base(4,4,0) +import Data.Typeable.Internal (TyCon(..), funTc, listTc) +# if MIN_VERSION_base(4,8,0) +import Data.Typeable.Internal (typeRepKinds) +# endif +#else +import Data.Typeable (TyCon, mkTyCon, tyConString, typeOf) +#endif + +import TextShow.Classes (TextShow(showb, showbPrec), showbParen, showbSpace) +import TextShow.Data.List () +import TextShow.Data.Typeable.Utils (showbArgs, showbTuple) +import TextShow.Utils (isTupleString) + +#include "inline.h" + +-- | Convert a 'TypeRep' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbTypeRepPrec :: Int -> TypeRep -> Builder +showbTypeRepPrec p tyrep = + case tys of + [] -> showbTyCon tycon + [x] | tycon == listTc -> singleton '[' <> showb x <> singleton ']' + [a,r] | tycon == funTc -> showbParen (p > 8) $ + showbPrec 9 a + <> " -> " + <> showbPrec 8 r + xs | isTupleTyCon tycon -> showbTuple xs + | otherwise -> showbParen (p > 9) $ + showbPrec p tycon + <> showbSpace + <> showbArgs showbSpace +#if MIN_VERSION_base(4,8,0) + (kinds ++ tys) +#else + tys +#endif + where + tycon = typeRepTyCon tyrep + tys = typeRepArgs tyrep +#if MIN_VERSION_base(4,8,0) + kinds = typeRepKinds tyrep +#endif + +#if !(MIN_VERSION_base(4,4,0)) +-- | The list 'TyCon'. +listTc :: TyCon +listTc = typeRepTyCon $ typeOf [()] + +-- | The function (@->@) 'TyCon'. +funTc :: TyCon +funTc = mkTyCon "->" +#endif + +-- | Does the 'TyCon' represent a tuple type constructor? +isTupleTyCon :: TyCon -> Bool +isTupleTyCon = isTupleString . tyConString +{-# INLINE isTupleTyCon #-} + +-- | Convert a 'TyCon' to a 'Builder'. +-- +-- /Since: 2/ +showbTyCon :: TyCon -> Builder +showbTyCon = fromString . tyConString +{-# INLINE showbTyCon #-} + +#if MIN_VERSION_base(4,4,0) +-- | Identical to 'tyConName'. Defined to avoid using excessive amounts of pragmas +-- with base-4.3 and earlier, which use 'tyConString'. +tyConString :: TyCon -> String +tyConString = tyConName +{-# INLINE tyConString #-} +#endif + +instance TextShow TypeRep where + showbPrec = showbTypeRepPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow TyCon where + showb = showbTyCon + INLINE_INST_FUN(showb)
+ src/TextShow/Data/Typeable/Utils.hs view
@@ -0,0 +1,31 @@+{-| +Module: TextShow.Data.Typeable.Utils +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Utility functions for showing data types in the @Typeable@ (or @OldTypeable@) module. +-} +module TextShow.Data.Typeable.Utils (showbArgs, showbTuple) where + +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, singleton) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(showbPrec)) + +-- | Helper function for showing a list of arguments, each separated by the given +-- 'Builder'. +showbArgs :: TextShow a => Builder -> [a] -> Builder +showbArgs _ [] = mempty +showbArgs _ [a] = showbPrec 10 a +showbArgs sep (a:as) = showbPrec 10 a <> sep <> showbArgs sep as + +-- | Helper function for showing a list of 'Show' instances in a tuple. +showbTuple :: TextShow a => [a] -> Builder +showbTuple args = singleton '(' <> showbArgs (singleton ',') args <> singleton ')' +{-# INLINE showbTuple #-}
+ src/TextShow/Data/Version.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Version +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for 'Version'. + +/Since: 2/ +-} +module TextShow.Data.Version ( + showbVersionPrec + , showbVersionConcrete + ) where + +import Data.List (intersperse) +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, fromString, singleton) +import Data.Version (Version(..)) + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (showb, showbPrec) +import TextShow.Data.Char () +import TextShow.Data.Integral () +import TextShow.Data.List () +import TextShow.TH.Internal (deriveTextShow) + +-- | Convert a 'Version' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbVersionPrec :: Int -> Version -> Builder +showbVersionPrec = showbPrec +{-# INLINE showbVersionPrec #-} + +-- | Provides one possible concrete representation for 'Version'. For +-- a version with 'versionBranch' @= [1,2,3]@ and 'versionTags' +-- @= [\"tag1\",\"tag2\"]@, the output will be @1.2.3-tag1-tag2@. +-- +-- /Since: 2/ +showbVersionConcrete :: Version -> Builder +showbVersionConcrete (Version branch tags) + = mconcat (intersperse (singleton '.') $ map showb branch) <> + mconcat (map ((singleton '-' <>) . fromString) tags) +{-# INLINE showbVersionConcrete #-} + +$(deriveTextShow ''Version)
+ src/TextShow/Data/Void.hs view
@@ -0,0 +1,31 @@+{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Data.Void +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Void' values. + +/Since: 2/ +-} +module TextShow.Data.Void (showbVoid) where + +import Data.Text.Lazy.Builder (Builder) +import Data.Void (Void, absurd) + +import Prelude () + +import TextShow.Classes (TextShow(showb)) + +-- | Since 'Void' values logically don't exist, attempting to convert one to a +-- 'Builder' will never terminate. +-- +-- /Since: 2/ +showbVoid :: Void -> Builder +showbVoid = absurd + +instance TextShow Void where + showb = showbVoid
+ src/TextShow/Debug/Trace.hs view
@@ -0,0 +1,369 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE OverloadedStrings #-} +{-| +Module: TextShow.Debug.Trace +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Functions for tracing and monitoring execution. + +These can be useful for investigating bugs or performance problems. +They should /not/ be used in production code. + +If you do not wish to require 'TextShow' instances for your @trace@ functions, +the "TextShow.Debug.Trace.TH" and "Text.Show.Text.Debug.Trace.Generic" modules +exist to convert the input to a debug message using Template Haskell or generics, +respectively. + +/Since: 2/ +-} +module TextShow.Debug.Trace ( + -- * Tracing + -- $tracing + tracet + , tracetl + , tracetId + , tracetlId + , traceTextShow + , traceTextShowId +#if MIN_VERSION_base(4,5,0) + , tracetStack + , tracetlStack +#endif + , tracetIO + , tracetlIO + , tracetM + , tracetlM + , traceTextShowM + +#if MIN_VERSION_base(4,5,0) + -- * Eventlog tracing + -- $eventlog_tracing + , tracetEvent + , tracetlEvent + , tracetEventIO + , tracetlEventIO +#endif +#if MIN_VERSION_base(4,7,0) + -- * Execution phase markers + -- $markers + , tracetMarker + , tracetlMarker + , tracetMarkerIO + , tracetlMarkerIO +#endif + ) where + +import Control.Monad (unless) + +import qualified Data.ByteString as BS (null, partition) +import Data.ByteString (ByteString, useAsCString) +import Data.ByteString.Internal (c2w) +import qualified Data.Text as TS (Text) +import Data.Text.Encoding (encodeUtf8) +import qualified Data.Text.Lazy as TL (Text) +import Data.Text.Lazy (toStrict) + +import Foreign.C.String (CString) + +#if MIN_VERSION_base(4,5,0) +import qualified Data.ByteString.Char8 as BS (pack) +import qualified Data.Text as TS (unpack) +import qualified Data.Text.Lazy as TL (unpack) + +import Debug.Trace + +import GHC.Stack (currentCallStack, renderStack) +#endif + +import Prelude () +import Prelude.Compat + +import System.IO.Unsafe (unsafePerformIO) + +import TextShow.Classes (TextShow, showt) +import TextShow.Instances () + +-- $tracing +-- +-- The @tracet(l)@, @traceTextShow@ and @tracet(l)IO@ functions print messages to an +-- output stream. They are intended for \"printf debugging\", that is: tracing the flow +-- of execution and printing interesting values. +-- +-- All these functions evaluate the message completely before printing +-- it; so if the message is not fully defined, none of it will be +-- printed. +-- +-- The usual output stream is 'System.IO.stderr'. For Windows GUI applications +-- (that have no stderr) the output is directed to the Windows debug console. +-- Some implementations of these functions may decorate the @Text@ that\'s +-- output to indicate that you\'re tracing. + +-- | The 'tracetIO' function outputs the trace message from the IO monad. +-- This sequences the output with respect to other IO actions. +-- +-- /Since: 2/ +tracetIO :: TS.Text -> IO () +tracetIO = traceIOByteString . encodeUtf8 + +-- | Like 'tracetIO' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlIO :: TL.Text -> IO () +tracetlIO = tracetIO . toStrict + +traceIOByteString :: ByteString -> IO () +traceIOByteString msg = useAsCString "%s\n" $ \cfmt -> do + -- NB: debugBelch can't deal with null bytes, so filter them + -- out so we don't accidentally truncate the message. See Trac #9395 + let (nulls, msg') = BS.partition (== c2w '\0') msg + useAsCString msg' $ \cmsg -> + debugBelch cfmt cmsg + unless (BS.null nulls) $ + useAsCString "WARNING: previous trace message had null bytes" $ \cmsg -> + debugBelch cfmt cmsg + +-- don't use debugBelch() directly, because we cannot call varargs functions +-- using the FFI. +foreign import ccall unsafe "HsBase.h debugBelch2" + debugBelch :: CString -> CString -> IO () + +{-| +The 'tracet' function outputs the trace message given as its first argument, +before returning the second argument as its result. + +For example, this returns the value of @f x@ but first outputs the message. + +> tracet ("calling f with x = " <> showt x) (f x) + +The 'tracet' function should /only/ be used for debugging, or for monitoring +execution. The function is not referentially transparent: its type indicates +that it is a pure function but it has the side effect of outputting the +trace message. + +/Since: 2/ +-} +tracet :: TS.Text -> a -> a +tracet = traceByteString . encodeUtf8 + +-- | Like 'tracet' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetl :: TL.Text -> a -> a +tracetl = tracet . toStrict + +{-# NOINLINE traceByteString #-} +traceByteString :: ByteString -> a -> a +traceByteString bs expr = unsafePerformIO $ do + traceIOByteString bs + return expr + +-- | Like 'tracet' but returns the message instead of a third value. +-- +-- /Since: 2/ +tracetId :: TS.Text -> TS.Text +tracetId a = tracet a a + +-- | Like 'tracetId' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlId :: TL.Text -> TL.Text +tracetlId a = tracetl a a + +{-| +Like 'tracet', but uses 'showt' on the argument to convert it to a 'TS.Text'. + +This makes it convenient for printing the values of interesting variables or +expressions inside a function. For example here we print the value of the +variables @x@ and @z@: + +> f x y = +> traceTextShow (x, z) $ result +> where +> z = ... +> ... + +/Since: 2/ +-} +traceTextShow :: TextShow a => a -> b -> b +traceTextShow = tracet . showt + +-- | Like 'traceTextShow' but returns the shown value instead of a third value. +-- +-- /Since: 2/ +traceTextShowId :: TextShow a => a -> a +traceTextShowId a = tracet (showt a) a + +{-| +Like 'tracet' but returning unit in an arbitrary 'Applicative' context. Allows for +convenient use in do-notation. Note that the application of 'tracet' is not an action +in the 'Applicative' context, as 'tracetIO' is in the 'IO' type. + +> ... = do +> x <- ... +> tracetM $ "x: " <> showt x +> y <- ... +> tracetM $ "y: " <> showt y + +/Since: 2/ +-} +tracetM :: Applicative f => TS.Text -> f () +tracetM text = tracet text $ pure () + +-- | Like 'tracetM' but accepts a lazy 'TL.Text' argument. +tracetlM :: Applicative f => TL.Text -> f () +tracetlM text = tracetl text $ pure () + +{-| +Like 'tracetM', but uses 'showt' on the argument to convert it to a 'TS.Text'. + +> ... = do +> x <- ... +> traceTextShowM x +> y <- ... +> traceTextShowM $ x + y + +/Since: 2/ +-} +traceTextShowM :: (TextShow a, Applicative f) => a -> f () +traceTextShowM = tracetM . showt + +#if MIN_VERSION_base(4,5,0) +-- | Like 'tracet' but additionally prints a call stack if one is +-- available. +-- +-- In the current GHC implementation, the call stack is only +-- availble if the program was compiled with @-prof@; otherwise +-- 'tracetStack' behaves exactly like 'tracet'. Entries in the call +-- stack correspond to @SCC@ annotations, so it is a good idea to use +-- @-fprof-auto@ or @-fprof-auto-calls@ to add SCC annotations automatically. +-- +-- /Since: 2/ +tracetStack :: TS.Text -> a -> a +tracetStack = traceStackByteString . encodeUtf8 + +-- | Like 'tracetStack' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlStack :: TL.Text -> a -> a +tracetlStack = tracetStack . toStrict + +traceStackByteString :: ByteString -> a -> a +traceStackByteString bs expr = unsafePerformIO $ do + traceIOByteString bs + stack <- currentCallStack + unless (null stack) . traceIOByteString . BS.pack $ renderStack stack + return expr + +-- $eventlog_tracing +-- +-- Eventlog tracing is a performance profiling system. These functions emit +-- extra events into the eventlog. In combination with eventlog profiling +-- tools these functions can be used for monitoring execution and +-- investigating performance problems. +-- +-- Currently only GHC provides eventlog profiling, see the GHC user guide for +-- details on how to use it. These function exists for other Haskell +-- implementations but no events are emitted. Note that the @Text@ message is +-- always evaluated, whether or not profiling is available or enabled. + +-- | The 'tracetEvent' function behaves like 'tracet' with the difference that +-- the message is emitted to the eventlog, if eventlog profiling is available +-- and enabled at runtime. +-- +-- It is suitable for use in pure code. In an IO context use 'tracetEventIO' +-- instead. +-- +-- Note that when using GHC's SMP runtime, it is possible (but rare) to get +-- duplicate events emitted if two CPUs simultaneously evaluate the same thunk +-- that uses 'traceEvent'. +-- +-- /Since: 2/ +tracetEvent :: TS.Text -> a -> a +tracetEvent = traceEvent . TS.unpack + +-- | Like 'tracetEvent' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlEvent :: TL.Text -> a -> a +tracetlEvent = traceEvent . TL.unpack + +-- | The 'tracetEventIO' function emits a message to the eventlog, if eventlog +-- profiling is available and enabled at runtime. +-- +-- Compared to 'tracetEvent', 'tracetEventIO' sequences the event with respect to +-- other IO actions. +-- +-- /Since: 2/ +tracetEventIO :: TS.Text -> IO () +tracetEventIO = traceEventIO . TS.unpack + +-- | Like 'tracetEventIO' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlEventIO :: TL.Text -> IO () +tracetlEventIO = traceEventIO . TL.unpack +#endif + +#if MIN_VERSION_base(4,7,0) +-- $markers +-- +-- When looking at a profile for the execution of a program we often want to +-- be able to mark certain points or phases in the execution and see that +-- visually in the profile. + +-- For example, a program might have several distinct phases with different +-- performance or resource behaviour in each phase. To properly interpret the +-- profile graph we really want to see when each phase starts and ends. +-- +-- Markers let us do this: we can annotate the program to emit a marker at +-- an appropriate point during execution and then see that in a profile. +-- +-- Currently this feature is only supported in GHC by the eventlog tracing +-- system, but in future it may also be supported by the heap profiling or +-- other profiling tools. These function exists for other Haskell +-- implementations but they have no effect. Note that the @Text@ message is +-- always evaluated, whether or not profiling is available or enabled. + +-- | The 'tracetMarker' function emits a marker to the eventlog, if eventlog +-- profiling is available and enabled at runtime. The 'TS.Text' is the name of +-- the marker. The name is just used in the profiling tools to help you keep +-- clear which marker is which. +-- +-- This function is suitable for use in pure code. In an IO context use +-- 'tracetMarkerIO' instead. +-- +-- Note that when using GHC's SMP runtime, it is possible (but rare) to get +-- duplicate events emitted if two CPUs simultaneously evaluate the same thunk +-- that uses 'traceMarker'. +-- +-- /Since: 2/ +tracetMarker :: TS.Text -> a -> a +tracetMarker msg = traceMarker $ TS.unpack msg + +-- | Like 'tracetMarker' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlMarker :: TL.Text -> a -> a +tracetlMarker msg = traceMarker $ TL.unpack msg + +-- | The 'tracetMarkerIO' function emits a marker to the eventlog, if eventlog +-- profiling is available and enabled at runtime. +-- +-- Compared to 'tracetMarker', 'tracetMarkerIO' sequences the event with respect to +-- other IO actions. +-- +-- /Since: 2/ +tracetMarkerIO :: TS.Text -> IO () +tracetMarkerIO = traceMarkerIO . TS.unpack + +-- | Like 'tracetMarkerIO' but accepts a lazy 'TL.Text' argument. +-- +-- /Since: 2/ +tracetlMarkerIO :: TL.Text -> IO () +tracetlMarkerIO = traceMarkerIO . TL.unpack +#endif
+ src/TextShow/Debug/Trace/Generic.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE FlexibleContexts #-} + +{-| +Module: TextShow.Debug.Trace.Generic +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Functions that trace the values of 'Generic' instances (even if they are not +instances of @TextShow@). + +/Since: 2/ +-} +module TextShow.Debug.Trace.Generic ( + genericTraceTextShow + , genericTraceTextShowId + , genericTraceTextShowM + ) where + +import Generics.Deriving.Base (Generic, Rep) + +import Prelude () +import Prelude.Compat + +import TextShow.Debug.Trace +import TextShow.Generic (GTextShow, genericShowt) + +-- | A 'Generic' implementation of 'traceTextShow'. +-- +-- /Since: 2/ +genericTraceTextShow :: (Generic a, GTextShow (Rep a)) => a -> b -> b +genericTraceTextShow = tracet . genericShowt + +-- | A 'Generic' implementation of 'traceTextShowId'. +-- +-- /Since: 2/ +genericTraceTextShowId :: (Generic a, GTextShow (Rep a)) => a -> a +genericTraceTextShowId a = tracet (genericShowt a) a + +-- | A 'Generic' implementation of 'traceShowM'. +-- +-- /Since: 2/ +genericTraceTextShowM :: (Generic a, GTextShow (Rep a), Applicative f) => a -> f () +genericTraceTextShowM = tracetM . genericShowt
+ src/TextShow/Debug/Trace/TH.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE TemplateHaskell #-} +{-| +Module: TextShow.Debug.Trace.TH +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Functions that splice traces into source code which take an arbitrary data type or +data family instance as an argument (even if it is not an instance of @TextShow@). You +need to enable the @TemplateHaskell@ language extension in order to use this module. + +/Since: 2/ +-} +module TextShow.Debug.Trace.TH ( + makeTraceTextShow + , makeTraceTextShowId + , makeTraceTextShowM + ) where + +import Language.Haskell.TH.Syntax (Name, Q, Exp) + +import TextShow.Debug.Trace +import TextShow.TH.Internal (makeShowt) + +-- | Generates a lambda expression which behaves like 'traceTextShow' (without +-- requiring a @TextShow@ instance). +-- +-- /Since: 2/ +makeTraceTextShow :: Name -> Q Exp +makeTraceTextShow name = [| tracet . $(makeShowt name) |] + +-- | Generates a lambda expression which behaves like 'traceTextShowId' (without +-- requiring a @TextShow@ instance). +-- +-- /Since: 2/ +makeTraceTextShowId :: Name -> Q Exp +makeTraceTextShowId name = [| \a -> tracet ($(makeShowt name) a) a |] + +-- | Generates a lambda expression which behaves like 'traceTextShowM' (without +-- requiring a @TextShow@ instance). +-- +-- /Since: 2/ +makeTraceTextShowM :: Name -> Q Exp +makeTraceTextShowM name = [| tracetM . $(makeShowt name) |]
+ src/TextShow/Foreign/C/Types.hs view
@@ -0,0 +1,477 @@+{-# LANGUAGE CPP #-} +#if MIN_VERSION_base(4,5,0) +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE StandaloneDeriving #-} +#endif +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Foreign.C.Types +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for Haskell newtypes corresponding to C +types in the Foreign Function Interface (FFI). + +/Since: 2/ +-} +module TextShow.Foreign.C.Types ( + showbCCharPrec + , showbCSCharPrec + , showbCUChar + , showbCShortPrec + , showbCUShort + , showbCIntPrec + , showbCUInt + , showbCLongPrec + , showbCULong + , showbCPtrdiffPrec + , showbCSize + , showbCWcharPrec + , showbCSigAtomicPrec + , showbCLLongPrec + , showbCULLong + , showbCIntPtrPrec + , showbCUIntPtr + , showbCIntMaxPrec + , showbCUIntMax + , showbCClockPrec + , showbCTimePrec +#if MIN_VERSION_base(4,4,0) + , showbCUSeconds + , showbCSUSecondsPrec +#endif + , showbCFloatPrec + , showbCDoublePrec + ) where + +import Data.Text.Lazy.Builder (Builder) + +import Foreign.C.Types + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.Data.Floating () +import TextShow.Data.Integral () + +#if !(MIN_VERSION_base(4,5,0)) +import Data.Int +import Data.Word + +import Unsafe.Coerce (unsafeCoerce) + +# include "HsBaseConfig.h" +# include "inline.h" +#endif + +-- | Convert a 'CChar' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCCharPrec :: Int -> CChar -> Builder +#if MIN_VERSION_base(4,5,0) +showbCCharPrec = showbPrec +{-# INLINE showbCCharPrec #-} +#else +showbCCharPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_CHAR -> Builder) +#endif + +-- | Convert a 'CSChar' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCSCharPrec :: Int -> CSChar -> Builder +#if MIN_VERSION_base(4,5,0) +showbCSCharPrec = showbPrec +{-# INLINE showbCSCharPrec #-} +#else +showbCSCharPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SIGNED_CHAR -> Builder) +#endif + +-- | Convert a 'CUChar' to a 'Builder'. +-- +-- /Since: 2/ +showbCUChar :: CUChar -> Builder +#if MIN_VERSION_base(4,5,0) +showbCUChar = showb +{-# INLINE showbCUChar #-} +#else +showbCUChar = unsafeCoerce (showb :: HTYPE_UNSIGNED_CHAR -> Builder) +#endif + +-- | Convert a 'CShort' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCShortPrec :: Int -> CShort -> Builder +#if MIN_VERSION_base(4,5,0) +showbCShortPrec = showbPrec +{-# INLINE showbCShortPrec #-} +#else +showbCShortPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SHORT -> Builder) +#endif + +-- | Convert a 'CUShort' to a 'Builder'. +-- +-- /Since: 2/ +showbCUShort :: CUShort -> Builder +#if MIN_VERSION_base(4,5,0) +showbCUShort = showb +{-# INLINE showbCUShort #-} +#else +showbCUShort = unsafeCoerce (showb :: HTYPE_UNSIGNED_SHORT -> Builder) +#endif + +-- | Convert a 'CInt' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCIntPrec :: Int -> CInt -> Builder +#if MIN_VERSION_base(4,5,0) +showbCIntPrec = showbPrec +{-# INLINE showbCIntPrec #-} +#else +showbCIntPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_INT -> Builder) +#endif + +-- | Convert a 'CUInt' to a 'Builder'. +-- +-- /Since: 2/ +showbCUInt :: CUInt -> Builder +#if MIN_VERSION_base(4,5,0) +showbCUInt = showb +{-# INLINE showbCUInt #-} +#else +showbCUInt = unsafeCoerce (showb :: HTYPE_UNSIGNED_INT -> Builder) +#endif + +-- | Convert a 'CLong' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCLongPrec :: Int -> CLong -> Builder +#if MIN_VERSION_base(4,5,0) +showbCLongPrec = showbPrec +{-# INLINE showbCLongPrec #-} +#else +showbCLongPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_LONG -> Builder) +#endif + +-- | Convert a 'CULong' to a 'Builder'. +-- +-- /Since: 2/ +showbCULong :: CULong -> Builder +#if MIN_VERSION_base(4,5,0) +showbCULong = showb +{-# INLINE showbCULong #-} +#else +showbCULong = unsafeCoerce (showb :: HTYPE_UNSIGNED_LONG -> Builder) +#endif + +-- | Convert a 'CPtrdiff' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCPtrdiffPrec :: Int -> CPtrdiff -> Builder +#if MIN_VERSION_base(4,5,0) +showbCPtrdiffPrec = showbPrec +{-# INLINE showbCPtrdiffPrec #-} +#else +showbCPtrdiffPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_PTRDIFF_T -> Builder) +#endif + +-- | Convert a 'CSize' to a 'Builder'. +-- +-- /Since: 2/ +showbCSize :: CSize -> Builder +#if MIN_VERSION_base(4,5,0) +showbCSize = showb +{-# INLINE showbCSize #-} +#else +showbCSize = unsafeCoerce (showb :: HTYPE_SIZE_T -> Builder) +#endif + +-- | Convert a 'CWchar' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCWcharPrec :: Int -> CWchar -> Builder +#if MIN_VERSION_base(4,5,0) +showbCWcharPrec = showbPrec +{-# INLINE showbCWcharPrec #-} +#else +showbCWcharPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_WCHAR_T -> Builder) +#endif + +-- | Convert a 'CSigAtomic' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCSigAtomicPrec :: Int -> CSigAtomic -> Builder +#if MIN_VERSION_base(4,5,0) +showbCSigAtomicPrec = showbPrec +{-# INLINE showbCSigAtomicPrec #-} +#else +showbCSigAtomicPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SIG_ATOMIC_T -> Builder) +#endif + +-- | Convert a 'CLLong' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCLLongPrec :: Int -> CLLong -> Builder +#if MIN_VERSION_base(4,5,0) +showbCLLongPrec = showbPrec +{-# INLINE showbCLLongPrec #-} +#else +showbCLLongPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_LONG_LONG -> Builder) +#endif + +-- | Convert a 'CULLong' to a 'Builder'. +-- +-- /Since: 2/ +showbCULLong :: CULLong -> Builder +#if MIN_VERSION_base(4,5,0) +showbCULLong = showb +{-# INLINE showbCULLong #-} +#else +showbCULLong = unsafeCoerce (showb :: HTYPE_UNSIGNED_LONG_LONG -> Builder) +#endif + +-- | Convert a 'CIntPtr' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCIntPtrPrec :: Int -> CIntPtr -> Builder +#if MIN_VERSION_base(4,5,0) +showbCIntPtrPrec = showbPrec +{-# INLINE showbCIntPtrPrec #-} +#else +showbCIntPtrPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_INTPTR_T -> Builder) +#endif + +-- | Convert a 'CUIntPtr' to a 'Builder'. +-- +-- /Since: 2/ +showbCUIntPtr :: CUIntPtr -> Builder +#if MIN_VERSION_base(4,5,0) +showbCUIntPtr = showb +{-# INLINE showbCUIntPtr #-} +#else +showbCUIntPtr = unsafeCoerce (showb :: HTYPE_UINTPTR_T -> Builder) +#endif + +-- | Convert a 'CIntMax' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCIntMaxPrec :: Int -> CIntMax -> Builder +#if MIN_VERSION_base(4,5,0) +showbCIntMaxPrec = showbPrec +{-# INLINE showbCIntMaxPrec #-} +#else +showbCIntMaxPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_INTMAX_T -> Builder) +#endif + +-- | Convert a 'CUIntMax' to a 'Builder'. +-- +-- /Since: 2/ +showbCUIntMax :: CUIntMax -> Builder +#if MIN_VERSION_base(4,5,0) +showbCUIntMax = showb +{-# INLINE showbCUIntMax #-} +#else +showbCUIntMax = unsafeCoerce (showb :: HTYPE_UINTMAX_T -> Builder) +#endif + +-- | Convert a 'CClock' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCClockPrec :: Int -> CClock -> Builder +#if MIN_VERSION_base(4,5,0) +showbCClockPrec = showbPrec +{-# INLINE showbCClockPrec #-} +#else +showbCClockPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_CLOCK_T -> Builder) +#endif + +-- | Convert a 'CTime' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCTimePrec :: Int -> CTime -> Builder +#if MIN_VERSION_base(4,5,0) +showbCTimePrec = showbPrec +{-# INLINE showbCTimePrec #-} +#else +showbCTimePrec = unsafeCoerce (showbPrec :: Int -> HTYPE_TIME_T -> Builder) +#endif + +#if MIN_VERSION_base(4,4,0) +-- | Convert a 'CUSeconds' value to a 'Builder'. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbCUSeconds :: CUSeconds -> Builder +# if MIN_VERSION_base(4,5,0) +showbCUSeconds = showb +{-# INLINE showbCUSeconds #-} +# else +showbCUSeconds = unsafeCoerce (showb :: HTYPE_USECONDS_T -> Builder) +# endif + +-- | Convert a 'CSUSeconds' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbCSUSecondsPrec :: Int -> CSUSeconds -> Builder +# if MIN_VERSION_base(4,5,0) +showbCSUSecondsPrec = showbPrec +{-# INLINE showbCSUSecondsPrec #-} +# else +showbCSUSecondsPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SUSECONDS_T -> Builder) +# endif +#endif + +-- | Convert a 'CFloat' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCFloatPrec :: Int -> CFloat -> Builder +#if MIN_VERSION_base(4,5,0) +showbCFloatPrec = showbPrec +{-# INLINE showbCFloatPrec #-} +#else +showbCFloatPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_FLOAT -> Builder) +#endif + +-- | Convert a 'CDouble' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCDoublePrec :: Int -> CDouble -> Builder +#if MIN_VERSION_base(4,5,0) +showbCDoublePrec = showbPrec +{-# INLINE showbCDoublePrec #-} +#else +showbCDoublePrec = unsafeCoerce (showbPrec :: Int -> HTYPE_DOUBLE -> Builder) +#endif + +#if MIN_VERSION_base(4,5,0) +deriving instance TextShow CChar +deriving instance TextShow CSChar +deriving instance TextShow CUChar +deriving instance TextShow CShort +deriving instance TextShow CUShort +deriving instance TextShow CInt +deriving instance TextShow CUInt +deriving instance TextShow CLong +deriving instance TextShow CULong +deriving instance TextShow CPtrdiff +deriving instance TextShow CSize +deriving instance TextShow CWchar +deriving instance TextShow CSigAtomic +deriving instance TextShow CLLong +deriving instance TextShow CULLong +deriving instance TextShow CIntPtr +deriving instance TextShow CUIntPtr +deriving instance TextShow CIntMax +deriving instance TextShow CUIntMax +deriving instance TextShow CClock +deriving instance TextShow CTime +# if MIN_VERSION_base(4,4,0) +deriving instance TextShow CUSeconds +deriving instance TextShow CSUSeconds +# endif +deriving instance TextShow CFloat +deriving instance TextShow CDouble +#else +instance TextShow CChar where + showbPrec = showbCCharPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CSChar where + showbPrec = showbCSCharPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CUChar where + showb = showbCUChar + INLINE_INST_FUN(showb) + +instance TextShow CShort where + showbPrec = showbCShortPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CUShort where + showb = showbCUShort + INLINE_INST_FUN(showb) + +instance TextShow CInt where + showbPrec = showbCIntPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CUInt where + showb = showbCUInt + INLINE_INST_FUN(showb) + +instance TextShow CLong where + showbPrec = showbCLongPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CULong where + showb = showbCULong + INLINE_INST_FUN(showb) + +instance TextShow CPtrdiff where + showbPrec = showbCPtrdiffPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CSize where + showb = showbCSize + INLINE_INST_FUN(showb) + +instance TextShow CWchar where + showbPrec = showbCWcharPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CSigAtomic where + showbPrec = showbCSigAtomicPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CLLong where + showbPrec = showbCLLongPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CULLong where + showb = showbCULLong + INLINE_INST_FUN(showb) + +instance TextShow CIntPtr where + showbPrec = showbCIntPtrPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CUIntPtr where + showb = showbCUIntPtr + INLINE_INST_FUN(showb) + +instance TextShow CIntMax where + showbPrec = showbCIntMaxPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CUIntMax where + showb = showbCUIntMax + INLINE_INST_FUN(showb) + +instance TextShow CClock where + showbPrec = showbCClockPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CTime where + showbPrec = showbCTimePrec + INLINE_INST_FUN(showbPrec) + +# if MIN_VERSION_base(4,4,0) +instance TextShow CUSeconds where + showb = showbCUSeconds + INLINE_INST_FUN(showb) + +instance TextShow CSUSeconds where + showbPrec = showbCSUSecondsPrec + INLINE_INST_FUN(showbPrec) +# endif + +instance TextShow CFloat where + showbPrec = showbCFloatPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow CDouble where + showbPrec = showbCDoublePrec + INLINE_INST_FUN(showbPrec) +#endif
+ src/TextShow/Foreign/Ptr.hs view
@@ -0,0 +1,115 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Foreign.Ptr +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for pointer types used in the Haskell +Foreign Function Interface (FFI). + +/Since: 2/ +-} +module TextShow.Foreign.Ptr ( + showbPtr + , showbFunPtr + , showbIntPtrPrec + , showbWordPtr + , showbForeignPtr + ) where + +import Data.Monoid.Compat ((<>)) +import Data.Semigroup (timesN) +import Data.Text.Lazy.Builder (Builder, singleton) + +import Foreign.ForeignPtr (ForeignPtr) +import Foreign.Ptr (FunPtr, IntPtr, WordPtr, castFunPtrToPtr) + +import GHC.ForeignPtr (unsafeForeignPtrToPtr) +import GHC.Num (wordToInteger) +import GHC.Ptr (Ptr(..)) +import GHC.Prim (addr2Int#, int2Word#, unsafeCoerce#) + +import TextShow.Classes (TextShow(showb, showbPrec), TextShow1(..)) +import TextShow.Data.Integral (showbHex, showbIntPrec, showbWord) +import TextShow.Utils (lengthB) + +#include "MachDeps.h" +#include "inline.h" + +-- | Convert a 'Ptr' to a 'Builder'. Note that this does not require the parameterized +-- type to be an instance of 'Show' itself. +-- +-- /Since: 2/ +showbPtr :: Ptr a -> Builder +showbPtr = showb +{-# INLINE showbPtr #-} + +-- | Convert a 'FunPtr' to a 'Builder'. Note that this does not require the +-- parameterized type to be an instance of 'Show' itself. +-- +-- /Since: 2/ +showbFunPtr :: FunPtr a -> Builder +showbFunPtr = showb +{-# INLINE showbFunPtr #-} + +-- | Convert an 'IntPtr' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbIntPtrPrec :: Int -> IntPtr -> Builder +showbIntPtrPrec p ip = showbIntPrec p $ unsafeCoerce# ip + +-- | Convert a 'WordPtr' to a 'Builder'. +-- +-- /Since: 2/ +showbWordPtr :: WordPtr -> Builder +showbWordPtr wp = showbWord $ unsafeCoerce# wp + +-- | Convert a 'ForeignPtr' to a 'Builder'. Note that this does not require the +-- parameterized type to be an instance of 'Show' itself. +-- +-- /Since: 2/ +showbForeignPtr :: ForeignPtr a -> Builder +showbForeignPtr = showb +{-# INLINE showbForeignPtr #-} + +instance TextShow (Ptr a) where + showbPrec = showbPrecWith undefined + INLINE_INST_FUN(showb) + +instance TextShow1 Ptr where + showbPrecWith _ _ (Ptr a) = padOut . showbHex $ wordToInteger (int2Word# (addr2Int# a)) + where + padOut :: Builder -> Builder + padOut ls = + singleton '0' <> singleton 'x' + <> timesN (fromIntegral . max 0 $ 2*SIZEOF_HSPTR - lengthB ls) (singleton '0') + <> ls + +instance TextShow (FunPtr a) where + showbPrec = showbPrecWith undefined + INLINE_INST_FUN(showb) + +instance TextShow1 FunPtr where + showbPrecWith _ _ = showb . castFunPtrToPtr + INLINE_INST_FUN(showbPrecWith) + +instance TextShow IntPtr where + showbPrec = showbIntPtrPrec + INLINE_INST_FUN(showbPrec) + +instance TextShow WordPtr where + showb = showbWordPtr + INLINE_INST_FUN(showb) + +instance TextShow (ForeignPtr a) where + showbPrec = showbPrecWith undefined + INLINE_INST_FUN(showb) + +instance TextShow1 ForeignPtr where + showbPrecWith _ _ = showb . unsafeForeignPtrToPtr + INLINE_INST_FUN(showbPrecWith)
+ src/TextShow/Functions.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Functions +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Optional 'TextShow', 'TextShow1', and 'TextShow2' instances for functions. + +/Since: 2/ +-} +module TextShow.Functions (showbFunction) where + +import Data.Text.Lazy.Builder (Builder) +import TextShow.Classes (TextShow(showb, showbPrec), TextShow1(..), TextShow2(..)) + +#include "inline.h" + +-- | Convert a function to a 'Builder'. +-- +-- /Since: 2/ +showbFunction :: (a -> b) -> Builder +showbFunction = showb +{-# INLINE showbFunction #-} + +instance TextShow (a -> b) where + showbPrec = showbPrecWith undefined + INLINE_INST_FUN(showb) + +instance TextShow1 ((->) a) where + showbPrecWith = showbPrecWith2 undefined + INLINE_INST_FUN(showbPrecWith) + +instance TextShow2 (->) where + showbPrecWith2 _ _ _ _ = "<function>" + INLINE_INST_FUN(showbPrecWith2)
+ src/TextShow/GHC/Conc/Windows.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE CPP #-} + +#if !defined(__GHCJS__) && defined(mingw32_HOST_OS) +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.Conc.Windows +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'ConsoleEvent'. +This module only exports functions if using Windows, and not using GHCJS. + +/Since: 2/ +-} +module TextShow.GHC.Conc.Windows ( +#if defined(__GHCJS__) || !defined(mingw32_HOST_OS) + ) where +#else + showbConsoleEvent + ) where + +import Data.Text.Lazy.Builder (Builder) + +import GHC.Conc.Windows (ConsoleEvent) + +import TextShow.Classes (showb) +import TextShow.TH.Internal (deriveTextShow) + +-- | Convert a 'ConsoleEvent' to a 'Builder'. +-- +-- /Since: 2/ +showbConsoleEvent :: ConsoleEvent -> Builder +showbConsoleEvent = showb +{-# INLINE showbConsoleEvent #-} + +$(deriveTextShow ''ConsoleEvent) +#endif
+ src/TextShow/GHC/Event.hs view
@@ -0,0 +1,81 @@+{-# LANGUAGE CPP #-} + +#if !defined(__GHCJS__) && !defined(mingw32_HOST_OS) && MIN_VERSION_base(4,4,0) +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.Event +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the @Event@ module. +This module only exports functions if using @base-4.4.0.0@ on a platform other +than Windows or GHCJS. + +/Since: 2/ +-} +module TextShow.GHC.Event ( +#if defined(__GHCJS__) || defined(mingw32_HOST_OS) || !(MIN_VERSION_base(4,4,0)) + ) where +#else + showbEvent + , showbFdKeyPrec +# if MIN_VERSION_base(4,8,1) + , showbLifetime +# endif + ) where + +import Data.Text.Lazy.Builder (Builder) +import GHC.Event (Event, FdKey) +import TextShow.Classes (TextShow(showb, showbPrec), FromStringShow(..)) + +# if MIN_VERSION_base(4,8,1) +import GHC.Event (Lifetime) +import TextShow.TH.Internal (deriveTextShow) +# endif + +-- | Convert an 'Event' to a 'Builder'. +-- This function is only available with @base-4.4.0.0@ or later and is not available +-- on Windows. +-- +-- /Since: 2/ +showbEvent :: Event -> Builder +showbEvent = showb . FromStringShow +{-# INLINE showbEvent #-} + +-- | Convert an 'FdKey' to a 'Builder' with the given precedence. +-- This function is only available with @base-4.4.0.0@ or later and is not available +-- on Windows. +-- +-- /Since: 2/ +showbFdKeyPrec :: Int -> FdKey -> Builder +showbFdKeyPrec p = showbPrec p . FromStringShow +{-# INLINE showbFdKeyPrec #-} + +# if MIN_VERSION_base(4,8,1) +-- | Convert a 'Lifetime' to a 'Builder'. +-- This function is only available with @base-4.8.1.0@ or later and is not available +-- on Windows. +-- +-- /Since: 2/ +showbLifetime :: Lifetime -> Builder +showbLifetime = showb +{-# INLINE showbLifetime #-} +# endif + +instance TextShow Event where + showb = showbEvent + {-# INLINE showb #-} + +instance TextShow FdKey where + showbPrec = showbFdKeyPrec + {-# INLINE showbPrec #-} + +# if MIN_VERSION_base(4,8,1) +$(deriveTextShow ''Lifetime) +# endif +#endif
+ src/TextShow/GHC/Fingerprint.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,4,0) +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.Fingerprint +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Fingerprint' values. +This module only exports functions if using @base-4.4.0.0@ or later. + +/Since: 2/ +-} +module TextShow.GHC.Fingerprint ( +#if !(MIN_VERSION_base(4,4,0)) + ) where +#else + showbFingerprint + ) where + +import Data.Monoid.Compat ((<>)) +import Data.Semigroup (timesN) +import Data.Text.Lazy.Builder (Builder, singleton) +import Data.Word (Word64) + +import GHC.Fingerprint.Type (Fingerprint(..)) + +import TextShow.Classes (TextShow(showb)) +import TextShow.Data.Integral (showbHex) +import TextShow.Utils (lengthB) + +-- | Convert a 'Fingerprint' to a 'Builder'. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbFingerprint :: Fingerprint -> Builder +showbFingerprint (Fingerprint w1 w2) = hex16 w1 <> hex16 w2 + where + hex16 :: Word64 -> Builder + hex16 i = let hex = showbHex i + in timesN (fromIntegral . max 0 $ 16 - lengthB hex) (singleton '0') <> hex + +instance TextShow Fingerprint where + showb = showbFingerprint + {-# INLINE showb #-} +#endif
+ src/TextShow/GHC/Generics.hs view
@@ -0,0 +1,199 @@+{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +{-| +Module: TextShow.GHC.Generics +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for generics-related data types. + +/Since: 2/ +-} +module TextShow.GHC.Generics ( + showbU1 + , showbPar1PrecWith + , showbRec1Prec + , showbRec1PrecWith + , showbK1PrecWith + , showbM1Prec + , showbM1PrecWith + , showbSumTypePrec + , showbSumTypePrecWith + , showbProductTypePrec + , showbProductTypePrecWith + , showbCompFunctorsPrec + , showbCompFunctorsPrecWith + , showbFixityPrec + , showbAssociativity + , showbArityPrec + ) where + +import Data.Text.Lazy.Builder (Builder) + +import Generics.Deriving.Base (U1(..), Par1, Rec1(..), K1(..), + M1(..), (:+:)(..), (:*:)(..), (:.:)(..), + Fixity, Associativity, Arity) + +import TextShow.Classes (TextShow(showb, showbPrec), TextShow1(..), TextShow2(..)) +import TextShow.Data.Integral () +import TextShow.TH.Internal (deriveTextShow, deriveTextShow1, makeShowbPrec, + makeShowbPrecWith, makeShowbPrecWith2) + +-- | Convert a 'U1' value to a 'Builder'. +-- +-- /Since: 2/ +showbU1 :: U1 p -> Builder +showbU1 = showb +{-# INLINE showbU1 #-} + +-- | Convert a 'Par1' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbPar1PrecWith :: (Int -> p -> Builder) -> Int -> Par1 p -> Builder +showbPar1PrecWith = showbPrecWith +{-# INLINE showbPar1PrecWith #-} + +-- | Convert a 'Rec1' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbRec1Prec :: TextShow (f p) => Int -> Rec1 f p -> Builder +showbRec1Prec = showbPrec +{-# INLINE showbRec1Prec #-} + +-- | Convert a 'Rec1' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbRec1PrecWith :: TextShow1 f => (Int -> p -> Builder) -> Int -> Rec1 f p -> Builder +showbRec1PrecWith = showbPrecWith +{-# INLINE showbRec1PrecWith #-} + +-- | Convert a 'K1' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbK1PrecWith :: (Int -> c -> Builder) -> Int -> K1 i c p -> Builder +showbK1PrecWith sp = showbPrecWith2 sp undefined +{-# INLINE showbK1PrecWith #-} + +-- | Convert an 'M1' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbM1Prec :: TextShow (f p) => Int -> M1 i c f p -> Builder +showbM1Prec = showbPrec +{-# INLINE showbM1Prec #-} + +-- | Convert an 'M1' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbM1PrecWith :: TextShow1 f => (Int -> p -> Builder) -> Int -> M1 i c f p -> Builder +showbM1PrecWith = showbPrecWith +{-# INLINE showbM1PrecWith #-} + +-- | Convert a '(:+:)' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbSumTypePrec :: (TextShow (f p), TextShow (g p)) => Int -> (f :+: g) p -> Builder +showbSumTypePrec = showbPrec +{-# INLINE showbSumTypePrec #-} + +-- | Convert a '(:+:)' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbSumTypePrecWith :: (TextShow1 f, TextShow1 g) => (Int -> p -> Builder) -> Int -> (f :+: g) p -> Builder +showbSumTypePrecWith = showbPrecWith +{-# INLINE showbSumTypePrecWith #-} + +-- | Convert a '(:*:)' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbProductTypePrec :: (TextShow (f p), TextShow (g p)) => Int -> (f :*: g) p -> Builder +showbProductTypePrec = showbPrec +{-# INLINE showbProductTypePrec #-} + +-- | Convert a '(:*:)' value to a 'Builder' with the given show function and precedence. +-- +-- /Since: 2/ +showbProductTypePrecWith :: (TextShow1 f, TextShow1 g) => (Int -> p -> Builder) -> Int -> (f :*: g) p -> Builder +showbProductTypePrecWith = showbPrecWith +{-# INLINE showbProductTypePrecWith #-} + +-- | Convert a '(:.:)' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCompFunctorsPrec :: TextShow (f (g p)) => Int -> (f :.: g) p -> Builder +showbCompFunctorsPrec = showbPrec +{-# INLINE showbCompFunctorsPrec #-} + +-- | Convert a '(:.:)' value to a 'Builder' with the given show function and precedence. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbCompFunctorsPrecWith :: (TextShow1 f, TextShow1 g) => (Int -> p -> Builder) -> Int -> (f :.: g) p -> Builder +showbCompFunctorsPrecWith = showbPrecWith +{-# INLINE showbCompFunctorsPrecWith #-} + +-- | Convert a 'Fixity' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbFixityPrec :: Int -> Fixity -> Builder +showbFixityPrec = showbPrec +{-# INLINE showbFixityPrec #-} + +-- | Convert an 'Associativity' value to a 'Builder'. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbAssociativity :: Associativity -> Builder +showbAssociativity = showb +{-# INLINE showbAssociativity #-} + +-- | Convert an 'Arity' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbArityPrec :: Int -> Arity -> Builder +showbArityPrec = showbPrec +{-# INLINE showbArityPrec #-} + +instance TextShow (U1 p) where + showbPrec = showbPrecWith undefined +$(deriveTextShow1 ''U1) + +$(deriveTextShow ''Par1) +$(deriveTextShow1 ''Par1) + +instance TextShow (f p) => TextShow (Rec1 f p) where + showbPrec = $(makeShowbPrec ''Rec1) +$(deriveTextShow1 ''Rec1) + +instance TextShow c => TextShow (K1 i c p) where + showbPrec = showbPrecWith undefined +instance TextShow c => TextShow1 (K1 i c) where + showbPrecWith = showbPrecWith2 showbPrec +instance TextShow2 (K1 i) where + showbPrecWith2 = $(makeShowbPrecWith2 ''K1) + +instance TextShow (f p) => TextShow (M1 i c f p) where + showbPrec = $(makeShowbPrec ''M1) +instance TextShow1 f => TextShow1 (M1 i c f) where + showbPrecWith = $(makeShowbPrecWith ''M1) + +instance (TextShow (f p), TextShow (g p)) => TextShow ((f :+: g) p) where + showbPrec = $(makeShowbPrec ''(:+:)) +$(deriveTextShow1 ''(:+:)) + +instance (TextShow (f p), TextShow (g p)) => TextShow ((f :*: g) p) where + showbPrec = $(makeShowbPrec ''(:*:)) +$(deriveTextShow1 ''(:*:)) + +instance TextShow (f (g p)) => TextShow ((f :.: g) p) where + showbPrec = $(makeShowbPrec ''(:.:)) +$(deriveTextShow1 ''(:.:)) + +$(deriveTextShow ''Fixity) +$(deriveTextShow ''Associativity) +$(deriveTextShow ''Arity)
+ src/TextShow/GHC/RTS/Flags.hs view
@@ -0,0 +1,265 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,8,0) +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.RTS.Flags +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the 'GHC.RTS.Flags' module. +This module only exports functions if using @base-4.8.0.0@ or later. + +/Since: 2/ +-} +module TextShow.GHC.RTS.Flags ( +#if !(MIN_VERSION_base(4,8,0)) + ) where +#else + showbRTSFlagsPrec + , showbGCFlagsPrec + , showbConcFlagsPrec + , showbMiscFlagsPrec + , showbDebugFlagsPrec + , showbCCFlagsPrec + , showbProfFlagsPrec + , showbTraceFlagsPrec + , showbTickyFlagsPrec + ) where + +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, singleton) + +import GHC.RTS.Flags + +import TextShow.Classes (TextShow(showb, showbPrec), FromStringShow(..)) +import TextShow.Data.Bool (showbBool) +import TextShow.Data.Char () +import TextShow.Data.Floating (showbDoublePrec) +import TextShow.Data.Integral (showbIntPrec, showbWord, showbWord64) +import TextShow.Data.List () +import TextShow.Data.Maybe (showbMaybePrecWith) +import TextShow.TH.Internal (deriveTextShow) + +# if __GLASGOW_HASKELL__ < 711 +import GHC.Show (appPrec) +import TextShow.Classes (showbParen) +# endif + +-- | Convert an 'RTSFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbRTSFlagsPrec :: Int -> RTSFlags -> Builder +showbRTSFlagsPrec = showbPrec +{-# INLINE showbRTSFlagsPrec #-} + +-- | Convert a 'GCFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbGCFlagsPrec :: Int -> GCFlags -> Builder +# if __GLASGOW_HASKELL__ >= 711 +showbGCFlagsPrec _ gcfs = +# else +showbGCFlagsPrec p gcfs = showbParen (p > appPrec) $ +# endif + "GCFlags {statsFile = " + <> showbMaybePrecWith showbPrec 0 (statsFile gcfs) + <> ", giveStats = " + <> showb (FromStringShow $ giveStats gcfs) + <> ", maxStkSize = " + <> showb (maxStkSize gcfs) + <> ", initialStkSize = " + <> showb (initialStkSize gcfs) + <> ", stkChunkSize = " + <> showb (stkChunkSize gcfs) + <> ", stkChunkBufferSize = " + <> showb (stkChunkBufferSize gcfs) + <> ", maxHeapSize = " + <> showb (maxHeapSize gcfs) + <> ", minAllocAreaSize = " + <> showb (minAllocAreaSize gcfs) + <> ", minOldGenSize = " + <> showb (minOldGenSize gcfs) + <> ", heapSizeSuggestion = " + <> showb (heapSizeSuggestion gcfs) + <> ", heapSizeSuggestionAuto = " + <> showbBool (heapSizeSuggestionAuto gcfs) + <> ", oldGenFactor = " + <> showbDoublePrec 0 (oldGenFactor gcfs) + <> ", pcFreeHeap = " + <> showbDoublePrec 0 (pcFreeHeap gcfs) + <> ", generations = " + <> showb (generations gcfs) + <> ", steps = " + <> showb (steps gcfs) + <> ", squeezeUpdFrames = " + <> showbBool (squeezeUpdFrames gcfs) + <> ", compact = " + <> showbBool (compact gcfs) + <> ", compactThreshold = " + <> showbDoublePrec 0 (compactThreshold gcfs) + <> ", sweep = " + <> showbBool (sweep gcfs) + <> ", ringBell = " + <> showbBool (ringBell gcfs) + <> ", frontpanel = " + <> showbBool (frontpanel gcfs) + <> ", idleGCDelayTime = " + <> showbWord64 (idleGCDelayTime gcfs) + <> ", doIdleGC = " + <> showbBool (doIdleGC gcfs) + <> ", heapBase = " + <> showbWord (heapBase gcfs) + <> ", allocLimitGrace = " + <> showbWord (allocLimitGrace gcfs) + <> singleton '}' + +-- | Convert a 'ConcFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbConcFlagsPrec :: Int -> ConcFlags -> Builder +showbConcFlagsPrec = showbPrec +{-# INLINE showbConcFlagsPrec #-} + +-- | Convert a 'MiscFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbMiscFlagsPrec :: Int -> MiscFlags -> Builder +showbMiscFlagsPrec = showbPrec +{-# INLINE showbMiscFlagsPrec #-} + +-- | Convert a 'DebugFlags' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbDebugFlagsPrec :: Int -> DebugFlags -> Builder +showbDebugFlagsPrec = showbPrec +{-# INLINE showbDebugFlagsPrec #-} + +-- | Convert a 'CCFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbCCFlagsPrec :: Int -> CCFlags -> Builder +# if __GLASGOW_HASKELL__ >= 711 +showbCCFlagsPrec _ ccfs = +# else +showbCCFlagsPrec p ccfs = showbParen (p > appPrec) $ +# endif + "CCFlags {doCostCentres = " + <> showb (FromStringShow $ doCostCentres ccfs) + <> ", profilerTicks = " + <> showbIntPrec 0 (profilerTicks ccfs) + <> ", msecsPerTick = " + <> showbIntPrec 0 (msecsPerTick ccfs) + <> singleton '}' + +-- | Convert a 'ProfFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbProfFlagsPrec :: Int -> ProfFlags -> Builder +# if __GLASGOW_HASKELL__ >= 711 +showbProfFlagsPrec _ pfs = +# else +showbProfFlagsPrec p pfs = showbParen (p > appPrec) $ +# endif + "ProfFlags {doHeapProfile = " + <> showb (FromStringShow $ doHeapProfile pfs) + <> ", heapProfileInterval = " + <> showbWord64 (heapProfileInterval pfs) + <> ", heapProfileIntervalTicks = " + <> showbWord (heapProfileIntervalTicks pfs) + <> ", includeTSOs = " + <> showbBool (includeTSOs pfs) + <> ", showCCSOnException = " + <> showbBool (showCCSOnException pfs) + <> ", maxRetainerSetSize = " + <> showbWord (maxRetainerSetSize pfs) + <> ", ccsLength = " + <> showbWord (ccsLength pfs) + <> ", modSelector = " + <> showbMaybePrecWith showbPrec 0 (modSelector pfs) + <> ", descrSelector = " + <> showbMaybePrecWith showbPrec 0 (descrSelector pfs) + <> ", typeSelector = " + <> showbMaybePrecWith showbPrec 0 (typeSelector pfs) + <> ", ccSelector = " + <> showbMaybePrecWith showbPrec 0 (ccSelector pfs) + <> ", ccsSelector = " + <> showbMaybePrecWith showbPrec 0 (ccsSelector pfs) + <> ", retainerSelector = " + <> showbMaybePrecWith showbPrec 0 (retainerSelector pfs) + <> ", bioSelector = " + <> showbMaybePrecWith showbPrec 0 (bioSelector pfs) + <> singleton '}' + +-- | Convert a 'TraceFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbTraceFlagsPrec :: Int -> TraceFlags -> Builder +# if __GLASGOW_HASKELL__ >= 711 +showbTraceFlagsPrec _ tfs = +# else +showbTraceFlagsPrec p tfs = showbParen (p > appPrec) $ +# endif + "TraceFlags {tracing = " + <> showb (FromStringShow $ tracing tfs) + <> ", timestamp = " + <> showbBool (timestamp tfs) + <> ", traceScheduler = " + <> showbBool (traceScheduler tfs) + <> ", traceGc = " + <> showbBool (traceGc tfs) + <> ", sparksSampled = " + <> showbBool (sparksSampled tfs) + <> ", sparksFull = " + <> showbBool (sparksFull tfs) + <> ", user = " + <> showbBool (user tfs) + <> singleton '}' + +-- | Convert a 'TickyFlags' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbTickyFlagsPrec :: Int -> TickyFlags -> Builder +showbTickyFlagsPrec = showbPrec +{-# INLINE showbTickyFlagsPrec #-} + +$(deriveTextShow ''RTSFlags) + +instance TextShow GCFlags where + showbPrec = showbGCFlagsPrec + {-# INLINE showbPrec #-} + +$(deriveTextShow ''ConcFlags) + +$(deriveTextShow ''MiscFlags) + +$(deriveTextShow ''DebugFlags) + +instance TextShow CCFlags where + showbPrec = showbCCFlagsPrec + {-# INLINE showbPrec #-} + +instance TextShow ProfFlags where + showbPrec = showbProfFlagsPrec + {-# INLINE showbPrec #-} + +instance TextShow TraceFlags where + showbPrec = showbTraceFlagsPrec + {-# INLINE showbPrec #-} + +$(deriveTextShow ''TickyFlags) +#endif
+ src/TextShow/GHC/StaticPtr.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,8,0) +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.StaticPtr +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'StaticPtrInfo' values. +This module only exports functions if using @base-4.8.0.0@ or later. + +/Since: 2/ +-} +module TextShow.GHC.StaticPtr ( +#if !(MIN_VERSION_base(4,8,0)) + ) where +#else + showbStaticPtrInfoPrec + ) where + +import Data.Text.Lazy.Builder (Builder) + +import GHC.StaticPtr (StaticPtrInfo) + +import TextShow.Classes (showbPrec) +import TextShow.Data.Char () +import TextShow.Data.Integral () +import TextShow.Data.List () +import TextShow.Data.Tuple () +import TextShow.TH.Internal (deriveTextShow) + +-- | Conver a 'StaticPtrInfo' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.8.0.0@ or later. +-- +-- /Since: 2/ +showbStaticPtrInfoPrec :: Int -> StaticPtrInfo -> Builder +showbStaticPtrInfoPrec = showbPrec +{-# INLINE showbStaticPtrInfoPrec #-} + +$(deriveTextShow ''StaticPtrInfo) +#endif
+ src/TextShow/GHC/Stats.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,5,0) +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.Stats +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'GCStats'. +This module only exports functions if using @base-4.5.0.0@ or later. + +/Since: 2/ +-} +module TextShow.GHC.Stats ( +#if !(MIN_VERSION_base(4,5,0)) + ) where +#else + showbGCStatsPrec + ) where + +import Data.Text.Lazy.Builder (Builder) + +import GHC.Stats (GCStats) + +import TextShow.Classes (showbPrec) +import TextShow.Data.Integral () +import TextShow.Data.Floating () +import TextShow.TH.Internal (deriveTextShow) + +-- | Convert a 'GCStats' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.5.0.0@ or later. +-- +-- /Since: 2/ +showbGCStatsPrec :: Int -> GCStats -> Builder +showbGCStatsPrec = showbPrec +{-# INLINE showbGCStatsPrec #-} + +$(deriveTextShow ''GCStats) +#endif
+ src/TextShow/GHC/TypeLits.hs view
@@ -0,0 +1,124 @@+{-# LANGUAGE CPP #-} + +#if MIN_VERSION_base(4,6,0) +# if !(MIN_VERSION_base(4,7,0)) +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE UndecidableInstances #-} +# endif + +{-# OPTIONS_GHC -fno-warn-orphans #-} +#endif +{-| +Module: TextShow.GHC.TypeLits +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for data types in the @GHC.TypeLits@ module. +This module only exports functions if using @base-4.6.0.0@ or later. + +/Since: 2/ +-} +module TextShow.GHC.TypeLits ( +#if MIN_VERSION_base(4,7,0) + showbSomeNatPrec + , showbSomeSymbol + ) where +#elif MIN_VERSION_base(4,6,0) + showbIsEven + , showbIsZero + , showbSingPrec + ) where +#else + ) where +#endif + +#if MIN_VERSION_base(4,6,0) + +import Data.Text.Lazy.Builder (Builder) +import TextShow.Classes (TextShow(showb, showbPrec)) + +# if MIN_VERSION_base(4,7,0) +import GHC.TypeLits (SomeNat(..), SomeSymbol(..), natVal, symbolVal) +import TextShow.Data.Char (showbString) +import TextShow.Data.Integral (showbIntegerPrec) +# else +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (singleton) +import GHC.TypeLits (IsEven(..), IsZero(..), Kind, Sing, SingE(fromSing)) +import TextShow.Data.Integral () +# endif + +# if MIN_VERSION_base(4,7,0) +-- | Convert a 'SomeNat' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.7.0.0@ or later. +-- +-- /Since: 2/ +showbSomeNatPrec :: Int -> SomeNat -> Builder +showbSomeNatPrec p (SomeNat x) = showbIntegerPrec p $ natVal x +{-# INLINE showbSomeNatPrec #-} + +-- | Convert a 'SomeSymbol' value to a 'Builder' with the given precedence. +-- This function is only available with @base-4.7.0.0@ or later. +-- +-- /Since: 2/ +showbSomeSymbol :: SomeSymbol -> Builder +showbSomeSymbol (SomeSymbol x) = showbString $ symbolVal x +{-# INLINE showbSomeSymbol #-} +# else +-- | Convert an 'IsEven' value to a 'Builder'. +-- This function is only available with @base-4.6@. +-- +-- /Since: 2/ +showbIsEven :: IsEven n -> Builder +showbIsEven IsEvenZero = singleton '0' +showbIsEven (IsEven x) = "(2 * " <> showb x <> singleton ')' +showbIsEven (IsOdd x) = "(2 * " <> showb x <> " + 1)" +{-# INLINE showbIsEven #-} + +-- | Convert an 'IsZero' value to a 'Builder'. +-- This function is only available with @base-4.6@. +-- +-- /Since: 2/ +showbIsZero :: IsZero n -> Builder +showbIsZero IsZero = singleton '0' +showbIsZero (IsSucc n) = singleton '(' <> showb n <> " + 1)" +{-# INLINE showbIsZero #-} + +-- | Convert a 'Sing' value to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbSingPrec :: (SingE (Kind :: k) rep, TextShow rep) => Int -> Sing (a :: k) -> Builder +showbSingPrec p = showbPrec p . fromSing +{-# INLINE showbSingPrec #-} +# endif + +# if MIN_VERSION_base(4,7,0) +instance TextShow SomeNat where + showbPrec = showbSomeNatPrec + {-# INLINE showbPrec #-} + +instance TextShow SomeSymbol where + showb = showbSomeSymbol + {-# INLINE showb #-} +# else +instance TextShow (IsEven n) where + showb = showbIsEven + {-# INLINE showb #-} + +instance TextShow (IsZero n) where + showb = showbIsZero + {-# INLINE showb #-} + +instance (SingE (Kind :: k) rep, TextShow rep) => TextShow (Sing (a :: k)) where + showbPrec = showbSingPrec + {-# INLINE showbPrec #-} +# endif + +#endif
+ src/TextShow/Generic.hs view
@@ -0,0 +1,444 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeOperators #-} + +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE DeriveGeneric #-} +#else +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeSynonymInstances #-} +#endif + +#if __GLASGOW_HASKELL__ >= 706 +{-# LANGUAGE PolyKinds #-} +#endif + +#if __GLASGOW_HASKELL__ >= 708 +{-# LANGUAGE StandaloneDeriving #-} +#endif +{-| +Module: TextShow.Generic +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Generic versions of 'TextShow' and 'TextShow1' class functions, as an alternative to +"TextShow.TH", which uses Template Haskell. Because there is no 'Generic2' +class, 'TextShow2' cannot be implemented generically. + +This implementation is based off of the @Generics.Deriving.Show@ module from the +@generic-deriving@ library. + +/Since: 2/ +-} +module TextShow.Generic ( + -- * Generic @show@ functions + -- $generics + + -- ** Understanding a compiler error + -- $generic_err + genericShowt + , genericShowtl + , genericShowtPrec + , genericShowtlPrec + , genericShowtList + , genericShowtlList + , genericShowb + , genericShowbPrec + , genericShowbList + , genericPrintT + , genericPrintTL + , genericHPrintT + , genericHPrintTL + , genericShowbPrecWith + , genericShowbPrec1 + -- * The 'GTextShow' and 'GTextShow1' classes + , GTextShow(..) + , GTextShow1(..) + , ConType(..) + ) where + +import Data.Monoid.Compat ((<>)) +import qualified Data.Text as TS (Text) +import qualified Data.Text.IO as TS (putStrLn, hPutStrLn) +import Data.Text.Lazy (toStrict) +import Data.Text.Lazy.Builder (Builder, fromString, singleton, toLazyText) +import qualified Data.Text.Lazy as TL (Text) +import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn) +import Data.Typeable (Typeable) + +import Generics.Deriving.Base +#if __GLASGOW_HASKELL__ < 702 +import qualified Generics.Deriving.TH as Generics (deriveAll) +#endif +import GHC.Show (appPrec, appPrec1) + +import Prelude () +import Prelude.Compat + +import System.IO (Handle) + +import TextShow.Classes (TextShow(showbPrec), TextShow1(..), + showbListWith, showbParen, showbSpace) +import TextShow.Instances () +import TextShow.Utils (isInfixTypeCon, isTupleString) + +#include "inline.h" + +{- $generics + +'TextShow' instances can be easily defined for data types that are 'Generic' instances. +The easiest way to do this is to use the @DeriveGeneric@ extension. + +@ +{-# LANGUAGE DeriveGeneric #-} +import GHC.Generics +import TextShow +import TextShow.Generic + +data D a = D a + deriving (Generic, Generic1) + +instance TextShow a => TextShow (D a) where + showbPrec = 'genericShowbPrec' + +instance TextShow1 D where + showbPrecWith = 'genericShowbPrecWith' +@ +-} + +{- $generic_err + +Suppose you intend to use 'genericShowbPrec' to define a 'TextShow' instance. + +@ +data Oops = Oops + -- forgot to add \"deriving Generic\" here! + +instance TextShow Oops where + showbPrec = 'genericShowbPrec' +@ + +If you forget to add a @deriving 'Generic'@ clause to your data type, at +compile-time, you will get an error message that begins roughly as follows: + +@ +No instance for ('GTextShow' (Rep Oops)) +@ + +This error can be confusing, but don't let it intimidate you. The correct fix is +simply to add the missing \"@deriving 'Generic'@\" clause. + +Similarly, if the compiler complains about not having an instance for @('GTextShow1' +(Rep1 Oops1))@, add a \"@deriving 'Generic1'@\" clause. +-} + +-- | A 'Generic' implementation of 'showt'. +-- +-- /Since: 2/ +genericShowt :: (Generic a, GTextShow (Rep a)) => a -> TS.Text +genericShowt = toStrict . genericShowtl + +-- | A 'Generic' implementation of 'showtl'. +-- +-- /Since: 2/ +genericShowtl :: (Generic a, GTextShow (Rep a)) => a -> TL.Text +genericShowtl = toLazyText . genericShowb + +-- | A 'Generic' implementation of 'showPrect'. +-- +-- /Since: 2/ +genericShowtPrec :: (Generic a, GTextShow (Rep a)) => Int -> a -> TS.Text +genericShowtPrec p = toStrict . genericShowtlPrec p + +-- | A 'Generic' implementation of 'showtlPrec'. +-- +-- /Since: 2/ +genericShowtlPrec :: (Generic a, GTextShow (Rep a)) => Int -> a -> TL.Text +genericShowtlPrec p = toLazyText . genericShowbPrec p + +-- | A 'Generic' implementation of 'showtList'. +-- +-- /Since: 2/ +genericShowtList :: (Generic a, GTextShow (Rep a)) => [a] -> TS.Text +genericShowtList = toStrict . genericShowtlList + +-- | A 'Generic' implementation of 'showtlList'. +-- +-- /Since: 2/ +genericShowtlList :: (Generic a, GTextShow (Rep a)) => [a] -> TL.Text +genericShowtlList = toLazyText . genericShowbList + +-- | A 'Generic' implementation of 'showb'. +-- +-- /Since: 2/ +genericShowb :: (Generic a, GTextShow (Rep a)) => a -> Builder +genericShowb = genericShowbPrec 0 + +-- | A 'Generic' implementation of 'showbPrec'. +-- +-- /Since: 2/ +genericShowbPrec :: (Generic a, GTextShow (Rep a)) => Int -> a -> Builder +genericShowbPrec p = gShowbPrec Pref p . from + +-- | A 'Generic' implementation of 'showbList'. +-- +-- /Since: 2/ +genericShowbList :: (Generic a, GTextShow (Rep a)) => [a] -> Builder +genericShowbList = showbListWith genericShowb + +-- | A 'Generic' implementation of 'printT'. +-- +-- /Since: 2/ +genericPrintT :: (Generic a, GTextShow (Rep a)) => a -> IO () +genericPrintT = TS.putStrLn . genericShowt + +-- | A 'Generic' implementation of 'printTL'. +-- +-- /Since: 2/ +genericPrintTL :: (Generic a, GTextShow (Rep a)) => a -> IO () +genericPrintTL = TL.putStrLn . genericShowtl + +-- | A 'Generic' implementation of 'hPrintT'. +-- +-- /Since: 2/ +genericHPrintT :: (Generic a, GTextShow (Rep a)) => Handle -> a -> IO () +genericHPrintT h = TS.hPutStrLn h . genericShowt + +-- | A 'Generic' implementation of 'hPrintTL'. +-- +-- /Since: 2/ +genericHPrintTL :: (Generic a, GTextShow (Rep a)) => Handle -> a -> IO () +genericHPrintTL h = TL.hPutStrLn h . genericShowtl + +-- | A 'Generic1' implementation of 'showbPrecWith'. +-- +-- /Since: 2/ +genericShowbPrecWith :: (Generic1 f, GTextShow1 (Rep1 f)) + => (Int -> a -> Builder) -> Int -> f a -> Builder +genericShowbPrecWith sp p = gShowbPrecWith Pref sp p . from1 + +-- | A 'Generic'/'Generic1' implementation of 'showbPrec1'. +-- +-- /Since: 2/ +genericShowbPrec1 :: (Generic a, Generic1 f, GTextShow (Rep a), GTextShow1 (Rep1 f)) + => Int -> f a -> Builder +genericShowbPrec1 = genericShowbPrecWith genericShowbPrec + +------------------------------------------------------------------------------- + +-- | Whether a constructor is a record ('Rec'), a tuple ('Tup'), is prefix ('Pref'), +-- or infix ('Inf'). +-- +-- /Since: 2/ +data ConType = Rec | Tup | Pref | Inf String + deriving ( Eq + , Ord + , Read + , Show + , Typeable +#if __GLASGOW_HASKELL__ >= 702 + , Generic +#endif + ) + +instance TextShow ConType where + showbPrec = genericShowbPrec + INLINE_INST_FUN(showbPrec) + +-- | Class of generic representation types ('Rep') that can be converted to +-- a 'Builder'. +-- +-- /Since: 2/ +class GTextShow f where + -- | This is used as the default generic implementation of 'showbPrec'. + gShowbPrec :: ConType -> Int -> f a -> Builder + -- | Whether a representation type has any constructors. + isNullary :: f a -> Bool + isNullary = error "generic showbPrec (isNullary): unnecessary case" +#if __GLASGOW_HASKELL__ >= 708 + {-# MINIMAL gShowbPrec #-} + +deriving instance Typeable GTextShow +#endif + +instance GTextShow U1 where + gShowbPrec _ _ U1 = mempty + isNullary _ = True + +instance TextShow c => GTextShow (K1 i c) where + gShowbPrec _ n (K1 a) = showbPrec n a + isNullary _ = False + +instance (Constructor c, GTextShow f) => GTextShow (C1 c f) where + gShowbPrec = gShowbConstructor gShowbPrec isNullary + +instance (Selector s, GTextShow f) => GTextShow (S1 s f) where + gShowbPrec = gShowbSelector gShowbPrec + isNullary (M1 x) = isNullary x + +instance GTextShow f => GTextShow (D1 d f) where + gShowbPrec t n (M1 x) = gShowbPrec t n x + +instance (GTextShow f, GTextShow g) => GTextShow (f :+: g) where + gShowbPrec t n (L1 x) = gShowbPrec t n x + gShowbPrec t n (R1 x) = gShowbPrec t n x + +instance (GTextShow f, GTextShow g) => GTextShow (f :*: g) where + gShowbPrec = gShowbProduct gShowbPrec gShowbPrec + -- If we have a product then it is not a nullary constructor + isNullary _ = False + +------------------------------------------------------------------------------- + +-- | Class of generic representation types ('Rep1') that can be converted to +-- a 'Builder' by lifting through a unary type constructor. +-- +-- /Since: 2/ +class GTextShow1 f where + -- | This is used as the default generic implementation of 'showbPrecWith'. + gShowbPrecWith :: ConType -> (Int -> a -> Builder) -> Int -> f a -> Builder + -- | Whether a representation type has any constructors. + isNullary1 :: f a -> Bool + isNullary1 = error "generic showbPrecWith (isNullary1): unnecessary case" +#if __GLASGOW_HASKELL__ >= 708 + {-# MINIMAL gShowbPrecWith #-} + +deriving instance Typeable GTextShow1 +#endif + +instance GTextShow1 U1 where + gShowbPrecWith _ _ _ U1 = mempty + isNullary1 _ = True + +instance GTextShow1 Par1 where + gShowbPrecWith _ sp n (Par1 p) = sp n p + isNullary1 _ = False + +instance TextShow c => GTextShow1 (K1 i c) where + gShowbPrecWith _ _ n (K1 a) = showbPrec n a + isNullary1 _ = False + +instance TextShow1 f => GTextShow1 (Rec1 f) where + gShowbPrecWith _ sp n (Rec1 r) = showbPrecWith sp n r + isNullary1 _ = False + +instance (Constructor c, GTextShow1 f) => GTextShow1 (C1 c f) where + gShowbPrecWith t sp = gShowbConstructor (flip gShowbPrecWith sp) isNullary1 t + +instance (Selector s, GTextShow1 f) => GTextShow1 (S1 s f) where + gShowbPrecWith t sp = gShowbSelector (flip gShowbPrecWith sp) t + isNullary1 (M1 x) = isNullary1 x + +instance GTextShow1 f => GTextShow1 (D1 d f) where + gShowbPrecWith t sp n (M1 x) = gShowbPrecWith t sp n x + +instance (GTextShow1 f, GTextShow1 g) => GTextShow1 (f :+: g) where + gShowbPrecWith t sp n (L1 x) = gShowbPrecWith t sp n x + gShowbPrecWith t sp n (R1 x) = gShowbPrecWith t sp n x + +instance (GTextShow1 f, GTextShow1 g) => GTextShow1 (f :*: g) where + gShowbPrecWith t sp = gShowbProduct (flip gShowbPrecWith sp) (flip gShowbPrecWith sp) t + -- If we have a product then it is not a nullary constructor + isNullary1 _ = False + +instance (TextShow1 f, GTextShow1 g) => GTextShow1 (f :.: g) where + gShowbPrecWith t sp n (Comp1 c) = showbPrecWith (gShowbPrecWith t sp) n c + isNullary1 _ = False + +------------------------------------------------------------------------------- +-- Shared code between GTextShow and GTextShow1 +------------------------------------------------------------------------------- + +gShowbConstructor :: forall c f p. Constructor c + => (ConType -> Int -> f p -> Builder) + -> (f p -> Bool) + -> ConType -> Int -> C1 c f p -> Builder +gShowbConstructor gs isNull _ n c@(M1 x) = case fixity of + Prefix -> showbParen ( n > appPrec + && not ( isNull x + || conIsTuple c +#if __GLASGOW_HASKELL__ >= 711 + || conIsRecord c +#endif + ) + ) $ + (if conIsTuple c + then mempty + else let cn = conName c + in showbParen (isInfixTypeCon cn) $ fromString cn + ) + <> (if isNull x || conIsTuple c + then mempty + else singleton ' ' + ) + <> showbBraces t (gs t appPrec1 x) + Infix _ m -> showbParen (n > m) . showbBraces t $ gs t (m+1) x + where + fixity :: Fixity + fixity = conFixity c + + t :: ConType + t = if conIsRecord c + then Rec + else case conIsTuple c of + True -> Tup + False -> case fixity of + Prefix -> Pref + Infix _ _ -> Inf $ conName c + + showbBraces :: ConType -> Builder -> Builder + showbBraces Rec b = singleton '{' <> b <> singleton '}' + showbBraces Tup b = singleton '(' <> b <> singleton ')' + showbBraces Pref b = b + showbBraces (Inf _) b = b + + conIsTuple :: C1 c f p -> Bool + conIsTuple = isTupleString . conName + +gShowbSelector :: Selector s + => (ConType -> Int -> f p -> Builder) + -> ConType -> Int -> S1 s f p -> Builder +gShowbSelector gs t n sel@(M1 x) + | selName sel == "" = gs t n x + | otherwise = fromString (selName sel) <> " = " <> gs t 0 x + +gShowbProduct :: (ConType -> Int -> f p -> Builder) + -> (ConType -> Int -> g p -> Builder) + -> ConType -> Int -> ((f :*: g) p) -> Builder +gShowbProduct gsa gsb t@Rec _ (a :*: b) = + gsa t 0 a + <> ", " + <> gsb t 0 b +gShowbProduct gsa gsb t@(Inf o) n (a :*: b) = + gsa t n a + <> showbSpace + <> infixOp + <> showbSpace + <> gsb t n b + where + infixOp :: Builder + infixOp = if isInfixTypeCon o + then fromString o + else singleton '`' <> fromString o <> singleton '`' +gShowbProduct gsa gsb t@Tup _ (a :*: b) = + gsa t 0 a + <> singleton ',' + <> gsb t 0 b +gShowbProduct gsa gsb t@Pref n (a :*: b) = + gsa t n a + <> showbSpace + <> gsb t n b + +------------------------------------------------------------------------------- + +#if __GLASGOW_HASKELL__ < 702 +$(Generics.deriveAll ''ConType) +#endif
+ src/TextShow/Instances.hs view
@@ -0,0 +1,65 @@+{-| +Module: TextShow.Instances +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Imports all orphan 'TextShow', 'TextShow1', and 'TextShow2' instances covered +by @text-show@ (except for the instances in `TextShow.Functions`, which are not +imported by default). +-} +module TextShow.Instances () where + +import TextShow.Control.Applicative () +import TextShow.Control.Concurrent () +import TextShow.Control.Exception () +import TextShow.Control.Monad.ST () + +import TextShow.Data.Array () +import TextShow.Data.Bool () +import TextShow.Data.ByteString () +import TextShow.Data.Char () +import TextShow.Data.Complex () +import TextShow.Data.Data () +import TextShow.Data.Dynamic () +import TextShow.Data.Either () +import TextShow.Data.Fixed () +import TextShow.Data.Floating () +import TextShow.Data.Functor.Identity () +import TextShow.Data.Integral () +import TextShow.Data.List () +import TextShow.Data.Maybe () +import TextShow.Data.Monoid () +import TextShow.Data.OldTypeable () +import TextShow.Data.Ord () +import TextShow.Data.Proxy () +import TextShow.Data.Ratio () +import TextShow.Data.Text () +import TextShow.Data.Tuple () +import TextShow.Data.Type.Coercion () +import TextShow.Data.Type.Equality () +import TextShow.Data.Typeable () +import TextShow.Data.Version () +import TextShow.Data.Void () + +import TextShow.Foreign.C.Types () +import TextShow.Foreign.Ptr () + +import TextShow.GHC.Conc.Windows () +import TextShow.GHC.Event () +import TextShow.GHC.Fingerprint () +import TextShow.GHC.Generics () +import TextShow.GHC.RTS.Flags () +import TextShow.GHC.StaticPtr () +import TextShow.GHC.Stats () +import TextShow.GHC.TypeLits () + +import TextShow.Numeric.Natural () + +import TextShow.System.Exit () +import TextShow.System.IO () +import TextShow.System.Posix.Types () + +import TextShow.Text.Read ()
+ src/TextShow/Numeric/Natural.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE CPP #-} +#if MIN_VERSION_base(4,8,0) +{-# LANGUAGE MagicHash #-} +#endif +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Numeric.Natural +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Natural's. + +/Since: 2/ +-} +module TextShow.Numeric.Natural (showbNaturalPrec) where + +import Data.Text.Lazy.Builder (Builder) + +#if MIN_VERSION_base(4,8,0) +import GHC.Integer.GMP.Internals (Integer(..)) +import GHC.Natural (Natural(..)) +import GHC.Types (Word(..)) + +import TextShow.Data.Integral (showbWord) +#else +import Numeric.Natural (Natural) +#endif + +import TextShow.Classes (TextShow(showbPrec)) +import TextShow.Data.Integral (showbIntegerPrec) + +#include "inline.h" + +-- | Convert a 'Natural' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbNaturalPrec :: Int -> Natural -> Builder +#if MIN_VERSION_base(4,8,0) +showbNaturalPrec _ (NatS# w#) = showbWord $ W# w# +showbNaturalPrec p (NatJ# bn) = showbIntegerPrec p $ Jp# bn +#else +showbNaturalPrec p = showbIntegerPrec p . toInteger +{-# INLINE showbNaturalPrec #-} +#endif + +instance TextShow Natural where + showbPrec = showbNaturalPrec + INLINE_INST_FUN(showbPrec)
+ src/TextShow/System/Exit.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.System.Exit +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'ExitCode'. + +/Since: 2/ +-} +module TextShow.System.Exit (showbExitCodePrec) where + +import Data.Text.Lazy.Builder (Builder) + +import System.Exit (ExitCode) + +import TextShow.Classes (showbPrec) +import TextShow.Data.Integral () +import TextShow.TH.Internal (deriveTextShow) + +-- | Convert an 'ExitCode' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbExitCodePrec :: Int -> ExitCode -> Builder +showbExitCodePrec = showbPrec +{-# INLINE showbExitCodePrec #-} + +$(deriveTextShow ''ExitCode)
+ src/TextShow/System/IO.hs view
@@ -0,0 +1,156 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.System.IO +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'IO'-related data types. + +/Since: 2/ +-} +module TextShow.System.IO ( + showbHandle + , showbIOMode + , showbBufferModePrec + , showbHandlePosn + , showbSeekMode + , showbTextEncoding +#if MIN_VERSION_base(4,4,0) + , showbCodingProgress + , showbCodingFailureMode +#endif + , showbNewline + , showbNewlineModePrec + ) where + +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy.Builder (Builder, fromString, singleton) + +import GHC.IO.Encoding.Types (TextEncoding(textEncodingName)) +#if MIN_VERSION_base(4,4,0) +import GHC.IO.Encoding.Failure (CodingFailureMode) +import GHC.IO.Encoding.Types (CodingProgress) +#endif +import GHC.IO.Handle (HandlePosn(..)) +import GHC.IO.Handle.Types (Handle(..)) + +import System.IO (BufferMode, IOMode, Newline, NewlineMode, SeekMode) + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.Data.Integral (showbIntegerPrec) +import TextShow.Data.Maybe () +import TextShow.TH.Internal (deriveTextShow) + +#include "inline.h" + +-- | Convert a 'Handle' to a 'Builder'. +-- +-- /Since: 2/ +showbHandle :: Handle -> Builder +showbHandle (FileHandle file _) = showbHandleFilePath file +showbHandle (DuplexHandle file _ _) = showbHandleFilePath file +{-# INLINE showbHandle #-} + +-- | Convert a 'Handle`'s 'FilePath' to a 'Builder'. +showbHandleFilePath :: FilePath -> Builder +showbHandleFilePath file = "{handle: " <> fromString file <> singleton '}' +{-# INLINE showbHandleFilePath #-} + +-- | Convert an 'IOMode' to a 'Builder'. +-- +-- /Since: 2/ +showbIOMode :: IOMode -> Builder +showbIOMode = showb +{-# INLINE showbIOMode #-} + +-- | Convert a 'BufferMode' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbBufferModePrec :: Int -> BufferMode -> Builder +showbBufferModePrec = showbPrec +{-# INLINE showbBufferModePrec #-} + +-- | Convert a 'HandlePosn' to a 'Builder'. +-- +-- /Since: 2/ +showbHandlePosn :: HandlePosn -> Builder +showbHandlePosn (HandlePosn h pos) + = showbHandle h <> " at position " <> showbIntegerPrec 0 pos +{-# INLINE showbHandlePosn #-} + +-- | Convert a 'SeekMode' to a 'Builder'. +-- +-- /Since: 2/ +showbSeekMode :: SeekMode -> Builder +showbSeekMode = showb +{-# INLINE showbSeekMode #-} + +-- | Convert a 'TextEncoding' to a 'Builder'. +-- +-- /Since: 2/ +showbTextEncoding :: TextEncoding -> Builder +showbTextEncoding = fromString . textEncodingName +{-# INLINE showbTextEncoding #-} + +#if MIN_VERSION_base(4,4,0) +-- | Convert a 'CodingProgress' to a 'Builder'. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbCodingProgress :: CodingProgress -> Builder +showbCodingProgress = showb +{-# INLINE showbCodingProgress #-} + +-- | Convert a 'CodingFailureMode' value to a 'Builder'. +-- This function is only available with @base-4.4.0.0@ or later. +-- +-- /Since: 2/ +showbCodingFailureMode :: CodingFailureMode -> Builder +showbCodingFailureMode = showb +{-# INLINE showbCodingFailureMode #-} +#endif + +-- | Convert a 'Newline' to a 'Builder'. +-- +-- /Since: 2/ +showbNewline :: Newline -> Builder +showbNewline = showb +{-# INLINE showbNewline #-} + +-- | Convert a 'NewlineMode' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbNewlineModePrec :: Int -> NewlineMode -> Builder +showbNewlineModePrec = showbPrec +{-# INLINE showbNewlineModePrec #-} + +instance TextShow Handle where + showb = showbHandle + INLINE_INST_FUN(showb) + +$(deriveTextShow ''IOMode) +$(deriveTextShow ''BufferMode) + +instance TextShow HandlePosn where + showb = showbHandlePosn + INLINE_INST_FUN(showb) + +$(deriveTextShow ''SeekMode) + +instance TextShow TextEncoding where + showb = showbTextEncoding + INLINE_INST_FUN(showb) + +#if MIN_VERSION_base(4,4,0) +$(deriveTextShow ''CodingProgress) +$(deriveTextShow ''CodingFailureMode) +#endif + +$(deriveTextShow ''Newline) +$(deriveTextShow ''NewlineMode)
+ src/TextShow/System/Posix/Types.hs view
@@ -0,0 +1,392 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +{-| +Module: TextShow.System.Posix.Types +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' functions for Haskell equivalents of POSIX data types. +Note that these functions are only available if the operating system supports them, +so some OSes (e.g., Windows) will not be able to use all of the functions in this +module. + +/Since: 2/ +-} +#include "HsBaseConfig.h" + +module TextShow.System.Posix.Types ( + showbFdPrec +#if defined(HTYPE_DEV_T) + , showbCDev +#endif +#if defined(HTYPE_INO_T) + , showbCIno +#endif +#if defined(HTYPE_MODE_T) + , showbCMode +#endif +#if defined(HTYPE_OFF_T) + , showbCOffPrec +#endif +#if defined(HTYPE_PID_T) + , showbCPidPrec +#endif +#if defined(HTYPE_SSIZE_T) + , showbCSsizePrec +#endif +#if defined(HTYPE_GID_T) + , showbCGid +#endif +#if defined(HTYPE_NLINK_T) + , showbCNlink +#endif +#if defined(HTYPE_UID_T) + , showbCUid +#endif +#if defined(HTYPE_CC_T) + , showbCCc +#endif +#if defined(HTYPE_SPEED_T) + , showbCSpeed +#endif +#if defined(HTYPE_TCFLAG_T) + , showbCTcflag +#endif +#if defined(HTYPE_RLIM_T) + , showbCRLim +#endif + ) where + +import Data.Text.Lazy.Builder (Builder) + +import System.Posix.Types + +import TextShow.Classes (TextShow(showb, showbPrec)) +import TextShow.Data.Integral () +import TextShow.Foreign.C.Types () + +#if !(MIN_VERSION_base(4,5,0)) +import Data.Int +import Data.Word + +import Unsafe.Coerce (unsafeCoerce) + +# include "HsBaseConfig.h" +# include "inline.h" +#endif + +#if defined(HTYPE_DEV_T) +-- | Convert a 'CDev' to a 'Builder'. +-- +-- /Since: 2/ +showbCDev :: CDev -> Builder +# if MIN_VERSION_base(4,5,0) +showbCDev = showb +{-# INLINE showbCDev #-} +# else +showbCDev = unsafeCoerce (showb :: HTYPE_DEV_T -> Builder) +# endif +#endif + +#if defined(HTYPE_INO_T) +-- | Convert a 'CIno' to a 'Builder'. +-- +-- /Since: 2/ +showbCIno :: CIno -> Builder +# if MIN_VERSION_base(4,5,0) +showbCIno = showb +{-# INLINE showbCIno #-} +# else +showbCIno = unsafeCoerce (showb :: HTYPE_INO_T -> Builder) +# endif +#endif + +#if defined(HTYPE_MODE_T) +-- | Convert a 'CMode' to a 'Builder'. +-- +-- /Since: 2/ +showbCMode :: CMode -> Builder +# if MIN_VERSION_base(4,5,0) +showbCMode = showb +{-# INLINE showbCMode #-} +# else +showbCMode = unsafeCoerce (showb :: HTYPE_MODE_T -> Builder) +# endif +#endif + +#if defined(HTYPE_OFF_T) +-- | Convert a 'COff' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCOffPrec :: Int -> COff -> Builder +# if MIN_VERSION_base(4,5,0) +showbCOffPrec = showbPrec +{-# INLINE showbCOffPrec #-} +# else +showbCOffPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_OFF_T -> Builder) +# endif +#endif + +#if defined(HTYPE_PID_T) +-- | Convert a 'CPid' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCPidPrec :: Int -> CPid -> Builder +# if MIN_VERSION_base(4,5,0) +showbCPidPrec = showbPrec +{-# INLINE showbCPidPrec #-} +# else +showbCPidPrec = unsafeCoerce (showbPrec :: Int -> HTYPE_PID_T -> Builder) +# endif +#endif + +#if defined(HTYPE_SSIZE_T) +-- | Convert a 'CSsize' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbCSsizePrec :: Int -> CSsize -> Builder +# if MIN_VERSION_base(4,5,0) +showbCSsizePrec = showbPrec +{-# INLINE showbCSsizePrec #-} +# else +showbCSsizePrec = unsafeCoerce (showbPrec :: Int -> HTYPE_SSIZE_T -> Builder) +# endif +#endif + +#if defined(HTYPE_GID_T) +-- | Convert a 'CGid' to a 'Builder'. +-- +-- /Since: 2/ +showbCGid :: CGid -> Builder +# if MIN_VERSION_base(4,5,0) +showbCGid = showb +{-# INLINE showbCGid #-} +# else +showbCGid = unsafeCoerce (showb :: HTYPE_GID_T -> Builder) +# endif +#endif + +#if defined(HTYPE_NLINK_T) +-- | Convert a 'CNlink' to a 'Builder'. +-- +-- /Since: 2/ +showbCNlink :: CNlink -> Builder +# if MIN_VERSION_base(4,5,0) +showbCNlink = showb +{-# INLINE showbCNlink #-} +# else +showbCNlink = unsafeCoerce (showb :: HTYPE_NLINK_T -> Builder) +# endif +#endif + +#if defined(HTYPE_UID_T) +-- | Convert a 'CUid' to a 'Builder'. +-- +-- /Since: 2/ +showbCUid :: CUid -> Builder +# if MIN_VERSION_base(4,5,0) +showbCUid = showb +{-# INLINE showbCUid #-} +# else +showbCUid = unsafeCoerce (showb :: HTYPE_UID_T -> Builder) +# endif +#endif + +#if defined(HTYPE_CC_T) +-- | Convert a 'CCc' to a 'Builder'. +-- +-- /Since: 2/ +showbCCc :: CCc -> Builder +# if MIN_VERSION_base(4,5,0) +showbCCc = showb +{-# INLINE showbCCc #-} +# else +showbCCc = unsafeCoerce (showb :: HTYPE_CC_T -> Builder) +# endif +#endif + +#if defined(HTYPE_SPEED_T) +-- | Convert a 'CSpeed' to a 'Builder'. +-- +-- /Since: 2/ +showbCSpeed :: CSpeed -> Builder +# if MIN_VERSION_base(4,5,0) +showbCSpeed = showb +{-# INLINE showbCSpeed #-} +# else +showbCSpeed = unsafeCoerce (showb :: HTYPE_SPEED_T -> Builder) +# endif +#endif + +#if defined(HTYPE_TCFLAG_T) +-- | Convert a 'CTcflag' to a 'Builder'. +-- +-- /Since: 2/ +showbCTcflag :: CTcflag -> Builder +# if MIN_VERSION_base(4,5,0) +showbCTcflag = showb +{-# INLINE showbCTcflag #-} +# else +showbCTcflag = unsafeCoerce (showb :: HTYPE_TCFLAG_T -> Builder) +# endif +#endif + +#if defined(HTYPE_RLIM_T) +-- | Convert a 'CRLim' to a 'Builder'. +-- +-- /Since: 2/ +showbCRLim :: CRLim -> Builder +# if MIN_VERSION_base(4,5,0) +showbCRLim = showb +{-# INLINE showbCRLim #-} +# else +showbCRLim = unsafeCoerce (showb :: HTYPE_RLIM_T -> Builder) +# endif +#endif + +-- | Convert an 'Fd' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbFdPrec :: Int -> Fd -> Builder +showbFdPrec = showbPrec +{-# INLINE showbFdPrec #-} + +#if MIN_VERSION_base(4,5,0) +# if defined(HTYPE_DEV_T) +deriving instance TextShow CDev +# endif + +# if defined(HTYPE_INO_T) +deriving instance TextShow CIno +# endif + +# if defined(HTYPE_MODE_T) +deriving instance TextShow CMode +# endif + +# if defined(HTYPE_OFF_T) +deriving instance TextShow COff +# endif + +# if defined(HTYPE_PID_T) +deriving instance TextShow CPid +# endif + +# if defined(HTYPE_SSIZE_T) +deriving instance TextShow CSsize +# endif + +# if defined(HTYPE_GID_T) +deriving instance TextShow CGid +# endif + +# if defined(HTYPE_NLINK_T) +deriving instance TextShow CNlink +# endif + +# if defined(HTYPE_UID_T) +deriving instance TextShow CUid +# endif + +# if defined(HTYPE_CC_T) +deriving instance TextShow CCc +# endif + +# if defined(HTYPE_SPEED_T) +deriving instance TextShow CSpeed +# endif + +# if defined(HTYPE_TCFLAG_T) +deriving instance TextShow CTcflag +# endif + +# if defined(HTYPE_RLIM_T) +deriving instance TextShow CRLim +# endif +#else +# if defined(HTYPE_DEV_T) +instance TextShow CDev where + showb = showbCDev + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_INO_T) +instance TextShow CIno where + showb = showbCIno + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_MODE_T) +instance TextShow CMode where + showb = showbCMode + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_OFF_T) +instance TextShow COff where + showbPrec = showbCOffPrec + INLINE_INST_FUN(showbPrec) +# endif + +# if defined(HTYPE_PID_T) +instance TextShow CPid where + showbPrec = showbCPidPrec + INLINE_INST_FUN(showbPrec) +# endif + +# if defined(HTYPE_SSIZE_T) +instance TextShow CSsize where + showbPrec = showbCSsizePrec + INLINE_INST_FUN(showbPrec) +# endif + +# if defined(HTYPE_GID_T) +instance TextShow CGid where + showb = showbCGid + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_NLINK_T) +instance TextShow CNlink where + showb = showbCNlink + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_UID_T) +instance TextShow CUid where + showb = showbCUid + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_CC_T) +instance TextShow CCc where + showb = showbCCc + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_SPEED_T) +instance TextShow CSpeed where + showb = showbCSpeed + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_TCFLAG_T) +instance TextShow CTcflag where + showb = showbCTcflag + INLINE_INST_FUN(showb) +# endif + +# if defined(HTYPE_RLIM_T) +instance TextShow CRLim where + showb = showbCRLim + INLINE_INST_FUN(showb) +# endif +#endif + +deriving instance TextShow Fd
+ src/TextShow/TH.hs view
@@ -0,0 +1,18 @@+{-| +Module: TextShow.TH +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Functions to mechanically derive 'TextShow', 'TextShow1', or 'TextShow2' instances, +or to splice @show@-related expressions into Haskell source code. You need to enable +the @TemplateHaskell@ language extension in order to use this module. + +/Since: 2/ +-} +module TextShow.TH (module TextShow.TH.Internal) where + +import TextShow.Instances () +import TextShow.TH.Internal
+ src/TextShow/TH/Internal.hs view
@@ -0,0 +1,1431 @@+{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE TemplateHaskell #-} +{-| +Module: TextShow.TH.Internal +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Functions to mechanically derive 'TextShow', 'TextShow1', or 'TextShow2' instances, +or to splice @show@-related expressions into Haskell source code. You need to enable +the @TemplateHaskell@ language extension in order to use this module. + +This implementation is loosely based off of the @Data.Aeson.TH@ module from the +@aeson@ library. +-} +module TextShow.TH.Internal ( + -- * 'deriveTextShow' + -- $deriveTextShow + deriveTextShow + -- * 'deriveTextShow1' + -- $deriveTextShow1 + , deriveTextShow1 + -- * 'deriveTextShow2' + -- $deriveTextShow2 + , deriveTextShow2 + -- * @make-@ functions + -- $make + , makeShowt + , makeShowtl + , makeShowtPrec + , makeShowtlPrec + , makeShowtList + , makeShowtlList + , makeShowb + , makeShowbPrec + , makeShowbList + , makePrintT + , makePrintTL + , makeHPrintT + , makeHPrintTL + , makeShowbPrecWith + , makeShowbPrec1 + , makeShowbPrecWith2 + , makeShowbPrec2 + ) where + +import Data.Function (on) +import Data.List.Compat (foldl', intersperse) +#if MIN_VERSION_template_haskell(2,7,0) +import Data.List.Compat (find) +#endif +import qualified Data.List.NonEmpty as NE +import Data.List.NonEmpty (NonEmpty(..), (<|)) +import qualified Data.Map as Map (fromList, lookup) +import Data.Map (Map) +import Data.Maybe (fromMaybe) +import Data.Monoid.Compat ((<>)) +import qualified Data.Set as Set +import Data.Set (Set) +import qualified Data.Text as TS () +import qualified Data.Text.IO as TS (putStrLn, hPutStrLn) +import Data.Text.Lazy (toStrict) +import Data.Text.Lazy.Builder (Builder, fromString, singleton, toLazyText) +import qualified Data.Text.Lazy as TL () +import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn) + +import GHC.Exts (Char(..), Double(..), Float(..), Int(..), Word(..)) +import GHC.Prim (Char#, Double#, Float#, Int#, Word#) +import GHC.Show (appPrec, appPrec1) + +import Language.Haskell.TH.Lib +import Language.Haskell.TH.Ppr hiding (appPrec) +import Language.Haskell.TH.Syntax + +import Prelude () +import Prelude.Compat + +import TextShow.Classes (TextShow(..), TextShow1(..), TextShow2(..), + showbListWith, showbParen, showbSpace) +import TextShow.Utils (isInfixTypeCon, isTupleString) + +------------------------------------------------------------------------------- +-- User-facing API +------------------------------------------------------------------------------- + +{- $deriveTextShow + +'deriveTextShow' automatically generates a 'TextShow' instance declaration for a data +type, a newtype, or a data family instance. This emulates what would (hypothetically) +happen if you could attach a @deriving 'TextShow'@ clause to the end of a data +declaration. + +Here are some examples of how to derive 'TextShow' for simple data types: + +@ +{-# LANGUAGE TemplateHaskell #-} +import TextShow.TH (deriveTextShow) + +data Letter = A | B | C +$('deriveTextShow' ''Letter) -- instance TextShow Letter where ... + +newtype Box a = Box a +$('deriveTextShow' ''Box) -- instance TextShow a => TextShow (Box a) where ... +@ + +If you are using @template-haskell-2.7.0.0@ or later (i.e., GHC 7.4 or later), +'deriveTextShow' can also be used to derive 'TextShow' instances for data family +instances (which requires the @-XTypeFamilies@ extension). To do so, pass the name of +a data or newtype instance constructor to 'deriveTextShow'. Note that the generated +code may require the @-XFlexibleInstances@ extension. Some examples: + +@ +{-# LANGUAGE FlexibleInstances, TemplateHaskell, TypeFamilies #-} +import TextShow.TH (deriveTextShow) + +class AssocClass a where + data AssocData a +instance AssocClass Int where + data AssocData Int = AssocDataInt1 Int | AssocDataInt2 Int Int +$('deriveTextShow' 'AssocDataInt1) -- instance TextShow (AssocData Int) where ... +-- Alternatively, one could use $(deriveTextShow 'AssocDataInt2) + +data family DataFam a b +newtype instance DataFam () b = DataFamB b +$('deriveTextShow' 'DataFamB) -- instance TextShow b => TextShow (DataFam () b) +@ + +Note that at the moment, there are some limitations: + +* The 'Name' argument to 'deriveTextShow' must not be a type synonym. + +* 'deriveTextShow' makes the assumption that all type variables of kind @*@ require a + 'TextShow' constraint when creating the type context. For example, if you have @data + Phantom a = Phantom@, then @('deriveTextShow' ''Phantom)@ will generate @instance + 'TextShow' a => 'TextShow' (Phantom a) where ...@, even though @'TextShow' a@ is + not required. If you want a proper 'TextShow' instance for @Phantom@, you will need + to use 'makeShowbPrec' (see the documentation of the 'make' functions for more + information). + +* 'deriveTextShow' lacks the ability to properly detect data types with higher-kinded + type parameters (e.g., @data HK f a = HK (f a)@) or with kinds other than @*@ + (e.g., @data List a (empty :: Bool)@). If you wish to derive 'TextShow' + instances for these data types, you will need to use 'makeShowbPrec' (see the + documentation of the 'make' functions for more information). + +* Some data constructors have arguments whose 'TextShow' instance depends on a + typeclass besides 'TextShow'. For example, consider @newtype MyFixed a = MyFixed + (Fixed a)@. @'Fixed' a@ is a 'TextShow' instance only if @a@ is an instance of both + @HasResolution@ and 'TextShow'. Unfortunately, 'deriveTextShow' cannot infer that + 'a' must be an instance of 'HasResolution', so it cannot create a 'TextShow' + instance for @MyFixed@. However, you can use 'makeShowbPrec' to get around this + (see the documentation of the 'make' functions for more information). + +-} + +-- | Generates a 'TextShow' instance declaration for the given data type or data +-- family instance. +-- +-- /Since: 2/ +deriveTextShow :: Name -> Q [Dec] +deriveTextShow = deriveTextShowClass TextShow + +{- $deriveTextShow1 + +'deriveTextShow1' automatically generates a 'Show1' instance declaration for a data +type, a newtype, or a data family instance that has at least one type variable. +This emulates what would (hypothetically) happen if you could attach a @deriving +'TextShow1'@ clause to the end of a data declaration. Examples: + +@ +{-# LANGUAGE TemplateHaskell #-} +import TextShow.TH (deriveTextShow1) + +data Stream a = Stream a (Stream a) +$('deriveTextShow1' ''Stream) -- instance Show1 TextStream where ... + +newtype WrappedFunctor f a = WrapFunctor (f a) +$('deriveTextShow1' ''WrappedFunctor) -- instance TextShow1 f => TextShow1 (WrappedFunctor f) where ... +@ + +The same restrictions that apply to 'deriveTextShow' also apply to 'deriveTextShow1', +with some caveats: + +* With 'deriveTextShow1', the last type variable must be of kind @*@. For other ones, + type variables of kind @*@ are assumed to require a 'TextShow' context, and type + variables of kind @* -> *@ are assumed to require a 'TextShow1' context. For more + complicated scenarios, use 'makeShowbPrecWith'. + +* If using @-XDatatypeContexts@, a datatype constraint cannot mention the last type + variable. For example, @data Ord a => Illegal a = Illegal a@ cannot have a derived + 'TextShow1' instance. + +* If the last type variable is used within a data field of a constructor, it must only + be used in the last argument of the data type constructor. For example, @data Legal a + = Legal (Either Int a)@ can have a derived 'TextShow1' instance, but @data Illegal a + = Illegal (Either a a)@ cannot. + +* Data family instances must be able to eta-reduce the last type variable. In other + words, if you have a instance of the form: + + @ + data family Family a1 ... an t + data instance Family e1 ... e2 v = ... + @ + + Then the following conditions must hold: + + 1. @v@ must be a type variable. + 2. @v@ must not be mentioned in any of @e1@, ..., @e2@. + +* In GHC 7.8, a bug exists that can cause problems when a data family declaration and + one of its data instances use different type variables, e.g., + + @ + data family Foo a b c + data instance Foo Int y z = Foo Int y z + $(deriveTextShow1 'Foo) + @ + + To avoid this issue, it is recommened that you use the same type variables in the + same positions in which they appeared in the data family declaration: + + @ + data family Foo a b c + data instance Foo Int b c = Foo Int b c + $(deriveTextShow1 'Foo) + @ + +-} + +-- | Generates a 'TextShow1' instance declaration for the given data type or data +-- family instance. +-- +-- /Since: 2/ +deriveTextShow1 :: Name -> Q [Dec] +deriveTextShow1 = deriveTextShowClass TextShow1 + +{- $deriveTextShow2 + +'deriveTextShow2' automatically generates a 'TextShow2' instance declaration for a data +type, a newtype, or a data family instance that has at least two type variables. +This emulates what would (hypothetically) happen if you could attach a @deriving +'TextShow2'@ clause to the end of a data declaration. Examples: + +@ +{-# LANGUAGE TemplateHaskell #-} +import TextShow.TH (deriveShow2) + +data OneOrNone a b = OneL a | OneR b | None +$('deriveTextShow2' ''OneOrNone) -- instance TextShow2 OneOrNone where ... + +newtype WrappedBifunctor f a b = WrapBifunctor (f a b) +$('deriveTextShow2' ''WrappedBifunctor) -- instance TextShow2 f => TextShow2 (WrappedBifunctor f) where ... +@ + +The same restrictions that apply to 'deriveTextShow' and 'deriveTextShow1' also apply +to 'deriveTextShow2', with some caveats: + +* With 'deriveTextShow2', the last type variables must both be of kind @*@. For other + ones, type variables of kind @*@ are assumed to require a 'TextShow' constraint, type + variables of kind @* -> *@ are assumed to require a 'TextShow1' constraint, and type + variables of kind @* -> * -> *@ are assumed to require a 'TextShow2' constraint. For + more complicated scenarios, use 'makeShowbPrecWith2'. + +* If using @-XDatatypeContexts@, a datatype constraint cannot mention either of the last + two type variables. For example, @data Ord a => Illegal a b = Illegal a b@ cannot + have a derived 'TextShow2' instance. + +* If either of the last two type variables is used within a data field of a constructor, + it must only be used in the last two arguments of the data type constructor. For + example, @data Legal a b = Legal (Int, Int, a, b)@ can have a derived 'TextShow2' + instance, but @data Illegal a b = Illegal (a, b, a, b)@ cannot. + +* Data family instances must be able to eta-reduce the last two type variables. In other + words, if you have a instance of the form: + + @ + data family Family a1 ... an t1 t2 + data instance Family e1 ... e2 v1 v2 = ... + @ + + Then the following conditions must hold: + + 1. @v1@ and @v2@ must be distinct type variables. + 2. Neither @v1@ not @v2@ must be mentioned in any of @e1@, ..., @e2@. + +-} + +-- | Generates a 'TextShow2' instance declaration for the given data type or data +-- family instance. +-- +-- /Since: 2/ +deriveTextShow2 :: Name -> Q [Dec] +deriveTextShow2 = deriveTextShowClass TextShow2 + +{- $make + +There may be scenarios in which you want to show an arbitrary data type or data +family instance without having to make the type an instance of 'TextShow'. For these +cases, "TextShow.TH" provide several functions (all prefixed with @make@) that +splice the appropriate lambda expression into your source code. Example: + +@ +{-# LANGUAGE OverloadedStrings, TemplateHaskell #-} +import TextShow.TH (makeShowT) + +data ADT = ADT + +whichADT :: Bool +whichADT = $(makeShowT ''ADT) ADT == \"ADT\" +@ + +@make@ functions are also useful for creating 'TextShow' instances for data types with +sophisticated type parameters. For example, 'deriveTextShow' cannot infer the correct +type context for @newtype HigherKinded f a = HigherKinded (f a)@, since @f@ is a +higher-kinded type parameter. However, it is still possible to derive a 'TextShow' +instance for @HigherKinded@ without too much trouble using 'makeShowbPrec': + +@ +{-# LANGUAGE FlexibleContexts, TemplateHaskell #-} +import TextShow +import TextShow.TH + +instance TextShow (f a) => TextShow (HigherKinded f a) where + showbPrec = $(makeShowbPrec ''HigherKinded) +@ + +-} + +-- | Generates a lambda expression which behaves like 'showt' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowt :: Name -> Q Exp +makeShowt name = [| toStrict . $(makeShowtl name) |] + +-- | Generates a lambda expression which behaves like 'showtl' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowtl :: Name -> Q Exp +makeShowtl name = [| toLazyText . $(makeShowb name) |] + +-- | Generates a lambda expression which behaves like 'showtPrec' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowtPrec :: Name -> Q Exp +makeShowtPrec name = [| \p -> toStrict . $(makeShowtlPrec name) p |] + +-- | Generates a lambda expression which behaves like 'showtlPrec' (without +-- requiring a 'TextShow' instance). +-- +-- /Since: 2/ +makeShowtlPrec :: Name -> Q Exp +makeShowtlPrec name = [| \p -> toLazyText . $(makeShowbPrec name) p |] + +-- | Generates a lambda expression which behaves like 'showtList' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowtList :: Name -> Q Exp +makeShowtList name = [| toStrict . $(makeShowtlList name) |] + +-- | Generates a lambda expression which behaves like 'showtlList' (without +-- requiring a 'TextShow' instance). +-- +-- /Since: 2/ +makeShowtlList :: Name -> Q Exp +makeShowtlList name = [| toLazyText . $(makeShowbList name) |] + +-- | Generates a lambda expression which behaves like 'showb' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowb :: Name -> Q Exp +makeShowb name = makeShowbPrec name `appE` [| zero |] + where + -- To prevent the generated TH code from having a type ascription + zero :: Int + zero = 0 + +-- | Generates a lambda expression which behaves like 'showbPrec' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowbPrec :: Name -> Q Exp +makeShowbPrec = makeShowbPrecClass TextShow + +-- | Generates a lambda expression which behaves like 'showbPrecWith' (without +-- requiring a 'TextShow1' instance). +-- +-- /Since: 2/ +makeShowbPrecWith :: Name -> Q Exp +makeShowbPrecWith = makeShowbPrecClass TextShow1 + +-- | Generates a lambda expression which behaves like 'showbPrec1' (without +-- requiring a 'TextShow1' instance). +-- +-- /Since: 2/ +makeShowbPrec1 :: Name -> Q Exp +makeShowbPrec1 name = [| $(makeShowbPrecWith name) showbPrec |] + +-- | Generates a lambda expression which behaves like 'showbPrecWith2' (without +-- requiring a 'TextShow2' instance). +-- +-- /Since: 2/ +makeShowbPrecWith2 :: Name -> Q Exp +makeShowbPrecWith2 = makeShowbPrecClass TextShow2 + +-- | Generates a lambda expression which behaves like 'showbPrecWith2' (without +-- requiring a 'TextShow2' instance). +-- +-- /Since: 2/ +makeShowbPrec2 :: Name -> Q Exp +makeShowbPrec2 name = [| $(makeShowbPrecWith2 name) showbPrec showbPrec |] + +-- | Generates a lambda expression which behaves like 'showbList' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeShowbList :: Name -> Q Exp +makeShowbList name = [| showbListWith $(makeShowb name) |] + +-- | Generates a lambda expression which behaves like 'printT' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makePrintT :: Name -> Q Exp +makePrintT name = [| TS.putStrLn . $(makeShowt name) |] + +-- | Generates a lambda expression which behaves like 'printTL' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makePrintTL :: Name -> Q Exp +makePrintTL name = [| TL.putStrLn . $(makeShowtl name) |] + +-- | Generates a lambda expression which behaves like 'hPrintT' (without requiring a +-- 'TextShow' instance). +-- +-- /Since: 2/ +makeHPrintT :: Name -> Q Exp +makeHPrintT name = [| \h -> TS.hPutStrLn h . $(makeShowt name) |] + +-- | Generates a lambda expression which behaves like 'hPrintTL' (without +-- requiring a 'TextShow' instance). +-- +-- /Since: 2/ +makeHPrintTL :: Name -> Q Exp +makeHPrintTL name = [| \h -> TL.hPutStrLn h . $(makeShowtl name) |] + +------------------------------------------------------------------------------- +-- Code generation +------------------------------------------------------------------------------- + +-- | Derive a TextShow(1)(2) instance declaration (depending on the TextShowClass +-- argument's value). +deriveTextShowClass :: TextShowClass -> Name -> Q [Dec] +deriveTextShowClass tsClass tyConName = do + info <- reify tyConName + case info of + TyConI{} -> deriveTextShowPlainTy tsClass tyConName +#if MIN_VERSION_template_haskell(2,7,0) + DataConI{} -> deriveTextShowDataFamInst tsClass tyConName + FamilyI (FamilyD DataFam _ _ _) _ -> + error $ ns ++ "Cannot use a data family name. Use a data family instance constructor instead." + FamilyI (FamilyD TypeFam _ _ _) _ -> + error $ ns ++ "Cannot use a type family name." + _ -> error $ ns ++ "The name must be of a plain type constructor or data family instance constructor." +#else + DataConI{} -> dataConIError + _ -> error $ ns ++ "The name must be of a plain type constructor." +#endif + where + ns :: String + ns = "TextShow.TH.deriveTextShow: " + +-- | Generates a TextShow(1)(2) instance declaration for a plain type constructor. +deriveTextShowPlainTy :: TextShowClass -> Name -> Q [Dec] +deriveTextShowPlainTy tsClass tyConName = + withTyCon tyConName fromCons + where + className :: Name + className = textShowClassNameTable tsClass + + fromCons :: Cxt -> [TyVarBndr] -> [Con] -> Q [Dec] + fromCons ctxt tvbs cons = (:[]) <$> + instanceD (return instanceCxt) + (return $ AppT (ConT className) instanceType) + (showbPrecDecs droppedNbs cons) + where + (instanceCxt, instanceType, droppedNbs) = + cxtAndTypePlainTy tsClass tyConName ctxt tvbs + +#if MIN_VERSION_template_haskell(2,7,0) +-- | Generates a TextShow(1)(2) instance declaration for a data family instance +-- constructor. +deriveTextShowDataFamInst :: TextShowClass -> Name -> Q [Dec] +deriveTextShowDataFamInst tsClass dataFamInstName = + withDataFamInstCon dataFamInstName fromDec + where + className :: Name + className = textShowClassNameTable tsClass + + fromDec :: [TyVarBndr] -> Cxt -> Name -> [Type] -> [Con] -> Q [Dec] + fromDec famTvbs ctxt parentName instTys cons = (:[]) <$> + instanceD (return instanceCxt) + (return $ AppT (ConT className) instanceType) + (showbPrecDecs droppedNbs cons) + where + (instanceCxt, instanceType, droppedNbs) = + cxtAndTypeDataFamInstCon tsClass parentName ctxt famTvbs instTys +#endif + +-- | Generates a declaration defining the primary function corresponding to a +-- particular class (showbPrec for TextShow, showbPrecWith for TextShow1, and +-- showbPrecWith2 for TextShow2). +showbPrecDecs :: [NameBase] -> [Con] -> [Q Dec] +showbPrecDecs nbs cons = + [ funD classFuncName + [ clause [] + (normalB $ makeTextShowForCons nbs cons) + [] + ] + ] + where + classFuncName :: Name + classFuncName = showbPrecNameTable . toEnum $ length nbs + +-- | Generates a lambda expression which behaves like showbPrec (for TextShow), +-- showbPrecWith (for TextShow1), or showbPrecWth2 (for TextShow2). +makeShowbPrecClass :: TextShowClass -> Name -> Q Exp +makeShowbPrecClass tsClass tyConName = do + info <- reify tyConName + case info of + TyConI{} -> withTyCon tyConName $ \ctxt tvbs decs -> + let (_, _, nbs) = cxtAndTypePlainTy tsClass tyConName ctxt tvbs + in makeTextShowForCons nbs decs +#if MIN_VERSION_template_haskell(2,7,0) + DataConI{} -> withDataFamInstCon tyConName $ \famTvbs ctxt parentName instTys cons -> + let (_, _, nbs) = cxtAndTypeDataFamInstCon tsClass parentName ctxt famTvbs instTys + in makeTextShowForCons nbs cons + FamilyI (FamilyD DataFam _ _ _) _ -> + error $ ns ++ "Cannot use a data family name. Use a data family instance constructor instead." + FamilyI (FamilyD TypeFam _ _ _) _ -> + error $ ns ++ "Cannot use a type family name." + _ -> error $ ns ++ "The name must be of a plain type constructor or data family instance constructor." +#else + DataConI{} -> dataConIError + _ -> error $ ns ++ "The name must be of a plain type constructor." +#endif + where + ns :: String + ns = "TextShow.TH.makeShowbPrec: " + +-- | Generates a lambda expression for showbPrec(With)(2) for the given constructors. +-- All constructors must be from the same type. +makeTextShowForCons :: [NameBase] -> [Con] -> Q Exp +makeTextShowForCons _ [] = error "Must have at least one data constructor" +makeTextShowForCons nbs cons = do + p <- newName "p" + value <- newName "value" + sps <- newNameList "sp" $ length nbs + let tvis = zip nbs sps + tsClass = toEnum $ length nbs + lamE (map varP $ sps ++ [p, value]) + . appsE + $ [ varE $ showbPrecConstNameTable tsClass + , caseE (varE value) $ map (makeTextShowForCon p tsClass tvis) cons + ] ++ map varE sps + ++ [varE p, varE value] + +-- | Generates a lambda expression for showbPrec(With)(2) for a single constructor. +makeTextShowForCon :: Name -> TextShowClass -> [TyVarInfo] -> Con -> Q Match +makeTextShowForCon _ _ _ (NormalC conName []) + = match (conP conName []) + (normalB [| fromString $(stringE (parenInfixConName conName "")) |]) + [] +makeTextShowForCon p tsClass tvis (NormalC conName [(_, argTy)]) = do + arg <- newName "arg" + + let showArg = makeTextShowForArg appPrec1 tsClass (nameBase conName) tvis argTy arg + namedArg = [| fromString $(stringE (parenInfixConName conName " ")) <> $(showArg) |] + + match (conP conName [varP arg]) + (normalB [| showbParen ($(varE p) > $(lift appPrec)) $(namedArg) |]) + [] +makeTextShowForCon p tsClass tvis (NormalC conName ts) = do + args <- newNameList "arg" $ length ts + + if isNonUnitTuple conName + then do + let showArgs = map (\(arg, (_, argTy)) -> makeTextShowForArg 0 tsClass (nameBase conName) tvis argTy arg) + (zip args ts) + parenCommaArgs = [| singleton '(' |] : intersperse [| singleton ',' |] showArgs + mappendArgs = foldr (`infixApp` [| (<>) |]) + [| singleton ')' |] + parenCommaArgs + + match (conP conName $ map varP args) + (normalB mappendArgs) + [] + else do + let showArgs = map (\(arg, (_, argTy)) -> makeTextShowForArg appPrec1 tsClass (nameBase conName) tvis argTy arg) + (zip args ts) + mappendArgs = foldr1 (\v q -> [| $(v) <> showbSpace <> $(q) |]) showArgs + namedArgs = [| fromString $(stringE (parenInfixConName conName " ")) <> $(mappendArgs) |] + + match (conP conName $ map varP args) + (normalB [| showbParen ($(varE p) > $(lift appPrec)) $(namedArgs) |]) + [] +makeTextShowForCon p tsClass tvis (RecC conName []) = makeTextShowForCon p tsClass tvis $ NormalC conName [] +makeTextShowForCon _p tsClass tvis (RecC conName ts) = do + args <- newNameList "arg" $ length ts + + let showArgs = concatMap (\(arg, (argName, _, argTy)) + -> [ [| fromString $(stringE (nameBase argName ++ " = ")) |] + , makeTextShowForArg 0 tsClass (nameBase conName) tvis argTy arg + , [| fromString ", " |] + ] + ) + (zip args ts) + braceCommaArgs = [| singleton '{' |] : take (length showArgs - 1) showArgs + mappendArgs = foldr (`infixApp` [| (<>) |]) + [| singleton '}' |] + braceCommaArgs + namedArgs = [| fromString $(stringE (parenInfixConName conName " ")) <> $(mappendArgs) |] + + match (conP conName $ map varP args) + (normalB +#if __GLASGOW_HASKELL__ >= 711 + namedArgs +#else + [| showbParen ($(varE _p) > $(lift appPrec)) $(namedArgs) |] +#endif + ) + [] +makeTextShowForCon p tsClass tvis (InfixC (_, alTy) conName (_, arTy)) = do + al <- newName "argL" + ar <- newName "argR" + info <- reify conName + + let conPrec = case info of + DataConI _ _ _ (Fixity prec _) -> prec + other -> error $ "TextShow.TH.makeTextShowForCon: Unsupported type: " ++ show other + opName = nameBase conName + infixOpE = if isInfixTypeCon opName + then [| fromString $(stringE $ " " ++ opName ++ " " ) |] + else [| fromString $(stringE $ " `" ++ opName ++ "` ") |] + + match (infixP (varP al) conName (varP ar)) + (normalB $ appE [| showbParen ($(varE p) > conPrec) |] + [| $(makeTextShowForArg (conPrec + 1) tsClass opName tvis alTy al) + <> $(infixOpE) + <> $(makeTextShowForArg (conPrec + 1) tsClass opName tvis arTy ar) + |] + ) + [] +makeTextShowForCon p tsClass tvis (ForallC tvbs _ con) = makeTextShowForCon p tsClass (removeForalled tvbs tvis) con + +-- | Generates a lambda expression for showbPrec(With)(2) for an argument of a +-- constructor. +makeTextShowForArg :: Int + -> TextShowClass + -> String + -> [TyVarInfo] + -> Type + -> Name + -> Q Exp +makeTextShowForArg p tsClass conName tvis ty tyExpName = do + ty' <- expandSyn ty + makeTextShowForArg' p tsClass conName tvis ty' tyExpName + +-- | Generates a lambda expression for showbPrec(With)(2) for an argument of a +-- constructor, after expanding all type synonyms. +makeTextShowForArg' :: Int + -> TextShowClass + -> String + -> [TyVarInfo] + -> Type + -> Name + -> Q Exp +makeTextShowForArg' p _ _ _ (ConT tyName) tyExpName = +#if __GLASGOW_HASKELL__ >= 711 +-- Starting with GHC 7.10, data types containing unlifted types with derived @Show@ +-- instances show hashed literals with actual hash signs, and negative hashed +-- literals are not surrounded with parentheses. + showE + where + tyVarE :: Q Exp + tyVarE = varE tyExpName + + showE :: Q Exp + showE | tyName == ''Char# = [| showbPrec 0 (C# $(tyVarE)) <> singleton '#' |] + | tyName == ''Double# = [| showbPrec 0 (D# $(tyVarE)) <> fromString "##" |] + | tyName == ''Float# = [| showbPrec 0 (F# $(tyVarE)) <> singleton '#' |] + | tyName == ''Int# = [| showbPrec 0 (I# $(tyVarE)) <> singleton '#' |] + | tyName == ''Word# = [| showbPrec 0 (W# $(tyVarE)) <> fromString "##" |] + | otherwise = [| showbPrec p $(tyVarE) |] +#else + [| showbPrec p $(expr) |] + where + tyVarE :: Q Exp + tyVarE = varE tyExpName + + expr :: Q Exp + expr | tyName == ''Char# = [| C# $(tyVarE) |] + | tyName == ''Double# = [| D# $(tyVarE) |] + | tyName == ''Float# = [| F# $(tyVarE) |] + | tyName == ''Int# = [| I# $(tyVarE) |] + | tyName == ''Word# = [| W# $(tyVarE) |] + | otherwise = tyVarE +#endif +makeTextShowForArg' p tsClass conName tvis ty tyExpName = + [| $(makeTextShowForType tsClass conName tvis ty) p $(varE tyExpName) |] + +-- | Generates a lambda expression for showbPrec(With)(2) for a specific type. +-- The generated expression depends on the number of type variables. +-- +-- 1. If the type is of kind * (T), apply showbPrec. +-- 2. If the type is of kind * -> * (T a), apply showbPrecWith $(makeTextShowForType a) +-- 3. If the type is of kind * -> * -> * (T a b), apply +-- showbPrecWith2 $(makeTextShowForType a) $(makeTextShowForType b) +makeTextShowForType :: TextShowClass + -> String + -> [TyVarInfo] + -> Type + -> Q Exp +makeTextShowForType _ _ tvis (VarT tyName) = + case lookup (NameBase tyName) tvis of + Just spExp -> varE spExp + Nothing -> [| showbPrec |] +makeTextShowForType tsClass conName tvis (SigT ty _) = makeTextShowForType tsClass conName tvis ty +makeTextShowForType tsClass conName tvis (ForallT tvbs _ ty) = makeTextShowForType tsClass conName (removeForalled tvbs tvis) ty +makeTextShowForType tsClass conName tvis ty = do + let tyArgs :: [Type] + tyCon :| tyArgs = unapplyTy ty + + numLastArgs :: Int + numLastArgs = min (fromEnum tsClass) (length tyArgs) + + lhsArgs, rhsArgs :: [Type] + (lhsArgs, rhsArgs) = splitAt (length tyArgs - numLastArgs) tyArgs + + tyVarNameBases :: [NameBase] + tyVarNameBases = map fst tvis + + itf <- isTyFamily tyCon + if any (`mentionsNameBase` tyVarNameBases) lhsArgs + || itf && any (`mentionsNameBase` tyVarNameBases) tyArgs + then outOfPlaceTyVarError conName tyVarNameBases numLastArgs + else appsE $ [ varE . showbPrecNameTable $ toEnum numLastArgs] + ++ map (makeTextShowForType tsClass conName tvis) rhsArgs + +------------------------------------------------------------------------------- +-- Template Haskell reifying and AST manipulation +------------------------------------------------------------------------------- + +-- | Extracts a plain type constructor's information. +withTyCon :: Name -- ^ Name of the plain type constructor + -> (Cxt -> [TyVarBndr] -> [Con] -> Q a) + -> Q a +withTyCon name f = do + info <- reify name + case info of + TyConI dec -> + case dec of + DataD ctxt _ tvbs cons _ -> f ctxt tvbs cons + NewtypeD ctxt _ tvbs con _ -> f ctxt tvbs [con] + other -> error $ ns ++ "Unsupported type " ++ show other ++ ". Must be a data type or newtype." + _ -> error $ ns ++ "The name must be of a plain type constructor." + where + ns :: String + ns = "TextShow.TH.withTyCon: " + +#if MIN_VERSION_template_haskell(2,7,0) +-- | Extracts a data family name's information. +withDataFam :: Name -- ^ Name of the data family + -> ([TyVarBndr] -> [Dec] -> Q a) + -> Q a +withDataFam name f = do + info <- reify name + case info of + FamilyI (FamilyD DataFam _ tvbs _) decs -> f tvbs decs + FamilyI (FamilyD TypeFam _ _ _) _ -> + error $ ns ++ "Cannot use a type family name." + other -> error $ ns ++ "Unsupported type " ++ show other ++ ". Must be a data family name." + where + ns :: String + ns = "TextShow.TH.withDataFam: " + +-- | Extracts a data family instance constructor's information. +withDataFamInstCon :: Name -- ^ Name of the data family instance constructor + -> ([TyVarBndr] -> Cxt -> Name -> [Type] -> [Con] -> Q a) + -> Q a +withDataFamInstCon dficName f = do + dficInfo <- reify dficName + case dficInfo of + DataConI _ _ parentName _ -> do + parentInfo <- reify parentName + case parentInfo of + FamilyI (FamilyD DataFam _ _ _) _ -> withDataFam parentName $ \famTvbs decs -> + let sameDefDec = flip find decs $ \dec -> + case dec of + DataInstD _ _ _ cons' _ -> any ((dficName ==) . constructorName) cons' + NewtypeInstD _ _ _ con _ -> dficName == constructorName con + _ -> error $ ns ++ "Must be a data or newtype instance." + + (ctxt, instTys, cons) = case sameDefDec of + Just (DataInstD ctxt' _ instTys' cons' _) -> (ctxt', instTys', cons') + Just (NewtypeInstD ctxt' _ instTys' con _) -> (ctxt', instTys', [con]) + _ -> error $ ns ++ "Could not find data or newtype instance constructor." + + in f famTvbs ctxt parentName instTys cons + _ -> error $ ns ++ "Data constructor " ++ show dficName ++ " is not from a data family instance." + other -> error $ ns ++ "Unsupported type " ++ show other ++ ". Must be a data family instance constructor." + where + ns :: String + ns = "TextShow.TH.withDataFamInstCon: " +#endif + +-- | Deduces the TextShow(1)(2) instance context, instance head, and eta-reduced +-- type variables for a plain data type constructor. +cxtAndTypePlainTy :: TextShowClass -- TextShow, TextShow1, or TextShow2 + -> Name -- The datatype's name + -> Cxt -- The datatype context + -> [TyVarBndr] -- The type variables + -> (Cxt, Type, [NameBase]) +cxtAndTypePlainTy tsClass tyConName dataCxt tvbs = + if remainingLength < 0 || not (wellKinded droppedKinds) -- If we have enough well-kinded type variables + then derivingKindError tsClass tyConName + else if any (`predMentionsNameBase` droppedNbs) dataCxt -- If the last type variable(s) are mentioned in a datatype context + then datatypeContextError tsClass instanceType + else (instanceCxt, instanceType, droppedNbs) + where + instanceCxt :: Cxt + instanceCxt = map (applyShowConstraint) + $ filter (needsConstraint tsClass . tvbKind) remaining + + instanceType :: Type + instanceType = applyTyCon tyConName $ map (VarT . tvbName) remaining + + remainingLength :: Int + remainingLength = length tvbs - fromEnum tsClass + + remaining, dropped :: [TyVarBndr] + (remaining, dropped) = splitAt remainingLength tvbs + + droppedKinds :: [Kind] + droppedKinds = map tvbKind dropped + + droppedNbs :: [NameBase] + droppedNbs = map (NameBase . tvbName) dropped + +#if MIN_VERSION_template_haskell(2,7,0) +-- | Deduces the TextShow(1)(2) instance context, instance head, and eta-reduced +-- type variables for a data family instnce constructor. +cxtAndTypeDataFamInstCon :: TextShowClass -- TextShow, TextShow1, or TextShow2 + -> Name -- The data family name + -> Cxt -- The datatype context + -> [TyVarBndr] -- The data family declaration's type variables + -> [Type] -- The data family instance types + -> (Cxt, Type, [NameBase]) +cxtAndTypeDataFamInstCon tsClass parentName dataCxt famTvbs instTysAndKinds = + if remainingLength < 0 || not (wellKinded droppedKinds) -- If we have enough well-kinded type variables + then derivingKindError tsClass parentName + else if any (`predMentionsNameBase` droppedNbs) dataCxt -- If the last type variable(s) are mentioned in a datatype context + then datatypeContextError tsClass instanceType + else if canEtaReduce remaining dropped -- If it is safe to drop the type variables + then (instanceCxt, instanceType, droppedNbs) + else etaReductionError instanceType + where + instanceCxt :: Cxt + instanceCxt = map (applyShowConstraint) + $ filter (needsConstraint tsClass . tvbKind) lhsTvbs + + -- We need to make sure that type variables in the instance head which have + -- TextShow constrains aren't poly-kinded, e.g., + -- + -- @ + -- instance TextShow a => TextShow (Foo (a :: k)) where + -- @ + -- + -- To do this, we remove every kind ascription (i.e., strip off every 'SigT'). + instanceType :: Type + instanceType = applyTyCon parentName + $ map unSigT remaining + + remainingLength :: Int + remainingLength = length famTvbs - fromEnum tsClass + + remaining, dropped :: [Type] + (remaining, dropped) = splitAt remainingLength rhsTypes + + droppedKinds :: [Kind] + droppedKinds = map tvbKind . snd $ splitAt remainingLength famTvbs + + droppedNbs :: [NameBase] + droppedNbs = map varTToNameBase dropped + + -- We need to mindful of an old GHC bug which causes kind variables appear in + -- @instTysAndKinds@ (as the name suggests) if (1) @PolyKinds@ is enabled, and + -- (2) either GHC 7.6 or 7.8 is being used (for more info, see + -- https://ghc.haskell.org/trac/ghc/ticket/9692). + -- + -- Since Template Haskell doesn't seem to have a mechanism for detecting which + -- language extensions are enabled, we do the next-best thing by counting + -- the number of distinct kind variables in the data family declaration, and + -- then dropping that number of entries from @instTysAndKinds@ + instTypes :: [Type] + instTypes = +# if __GLASGOW_HASKELL__ >= 710 || !(MIN_VERSION_template_haskell(2,8,0)) + instTysAndKinds +# else + drop (Set.size . Set.unions $ map (distinctKindVars . tvbKind) famTvbs) + instTysAndKinds +# endif + + lhsTvbs :: [TyVarBndr] + lhsTvbs = map (uncurry replaceTyVarName) + . filter (isTyVar . snd) + . take remainingLength + $ zip famTvbs rhsTypes + + -- In GHC 7.8, only the @Type@s up to the rightmost non-eta-reduced type variable + -- in @instTypes@ are provided (as a result of this extremely annoying bug: + -- https://ghc.haskell.org/trac/ghc/ticket/9692). This is pretty inconvenient, + -- as it makes it impossible to come up with the correct 'TextShow1' or 'TextShow2' + -- instances in some cases. For example, consider the following code: + -- + -- @ + -- data family Foo a b c + -- data instance Foo Int y z = Foo Int y z + -- $(deriveTextShow2 'Foo) + -- @ + -- + -- Due to the aformentioned bug, Template Haskell doesn't tell us the names of + -- either of type variables in the data instance (@y@ and @z@). As a result, we + -- won't know which fields of the 'Foo' constructor to apply the show functions, + -- which will result in an incorrect instance. Urgh. + -- + -- A workaround is to ensure that you use the exact same type variables, in the + -- exact same order, in the data family declaration and any data or newtype + -- instances: + -- + -- @ + -- data family Foo a b c + -- data instance Foo Int b c = Foo Int b c + -- $(deriveTextShow2 'Foo) + -- @ + -- + -- Thankfully, other versions of GHC don't seem to have this bug. + rhsTypes :: [Type] + rhsTypes = +# if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 + instTypes ++ map tvbToType + (drop (length instTypes) + famTvbs) +# else + instTypes +# endif +#endif + +-- | Given a TyVarBndr, apply a TextShow(1)(2) constraint to it, depending +-- on its kind. +applyShowConstraint :: TyVarBndr -> Pred +applyShowConstraint (PlainTV name) = applyClass ''TextShow name +applyShowConstraint (KindedTV name kind) = applyClass className name + where + className :: Name + className = textShowClassNameTable . toEnum $ numKindArrows kind + +-- | Can a kind signature inhabit a TextShow(1)(2) constraint? +-- +-- TextShow: k +-- TextShow1: k1 -> k2 +-- TextShow2: k1 -> k2 -> k3 +needsConstraint :: TextShowClass -> Kind -> Bool +needsConstraint tsClass kind = + fromEnum tsClass >= numKindArrows kind + && canRealizeKindStarChain kind + +------------------------------------------------------------------------------- +-- Error messages +------------------------------------------------------------------------------- + +-- | Either the given data type doesn't have enough type variables, or one of +-- the type variables to be eta-reduced cannot realize kind *. +derivingKindError :: TextShowClass -> Name -> a +derivingKindError tsClass tyConName = error + . showString "Cannot derive well-kinded instance of form ‘" + . showString className + . showChar ' ' + . showParen True + ( showString (nameBase tyConName) + . showString " ..." + ) + . showString "‘\n\tClass " + . showString className + . showString " expects an argument of kind " + . showString (pprint . createKindChain $ fromEnum tsClass) + $ "" + where + className :: String + className = nameBase $ textShowClassNameTable tsClass + +-- | One of the last type variables cannot be eta-reduced (see the canEtaReduce +-- function for the criteria it would have to meet). +etaReductionError :: Type -> a +etaReductionError instanceType = error $ + "Cannot eta-reduce to an instance of form \n\tinstance (...) => " + ++ pprint instanceType + +-- | The data type has a DatatypeContext which mentions one of the eta-reduced +-- type variables. +datatypeContextError :: TextShowClass -> Type -> a +datatypeContextError tsClass instanceType = error + . showString "Can't make a derived instance of ‘" + . showString (pprint instanceType) + . showString "‘:\n\tData type ‘" + . showString className + . showString "‘ must not have a class context involving the last type argument(s)" + $ "" + where + className :: String + className = nameBase $ textShowClassNameTable tsClass + +-- | The data type mentions one of the n eta-reduced type variables in a place other +-- than the last nth positions of a data type in a constructor's field. +outOfPlaceTyVarError :: String -> [NameBase] -> Int -> a +outOfPlaceTyVarError conName tyVarNames numLastArgs = error + . showString "Constructor ‘" + . showString conName + . showString "‘ must use the type variable" + . plural id (showChar 's') + . showString " " + . showsPrec 0 tyVarNames + . showString " only in the last " + . plural id (showsPrec 0 numLastArgs) + . showString "argument" + . plural id (showChar 's') + . showString " of a data type" + $ "" + where + plural :: ShowS -> ShowS -> ShowS + plural one many = case numLastArgs of + 1 -> one + _ -> many + +#if !(MIN_VERSION_template_haskell(2,7,0)) +-- | Template Haskell didn't list all of a data family's instances upon reification +-- until template-haskell-2.7.0.0, which is necessary for a derived TextShow(1)(2) +-- instance to work. +dataConIError :: a +dataConIError = error + . showString "Cannot use a data constructor." + . showString "\n\t(Note: if you are trying to derive TextShow for a" + . showString "\n\ttype family, use GHC >= 7.4 instead.)" + $ "" +#endif + +------------------------------------------------------------------------------- +-- Expanding type synonyms +------------------------------------------------------------------------------- + +-- | Expands all type synonyms in a type. Written by Dan Rosén in the +-- @genifunctors@ package (licensed under BSD3). +expandSyn :: Type -> Q Type +expandSyn (ForallT tvs ctx t) = fmap (ForallT tvs ctx) $ expandSyn t +expandSyn t@AppT{} = expandSynApp t [] +expandSyn t@ConT{} = expandSynApp t [] +expandSyn (SigT t _) = expandSyn t -- Ignore kind synonyms +expandSyn t = return t + +expandSynApp :: Type -> [Type] -> Q Type +expandSynApp (AppT t1 t2) ts = do + t2' <- expandSyn t2 + expandSynApp t1 (t2':ts) +expandSynApp (ConT n) ts | nameBase n == "[]" = return $ foldl' AppT ListT ts +expandSynApp t@(ConT n) ts = do + info <- reify n + case info of + TyConI (TySynD _ tvs rhs) -> + let (ts', ts'') = splitAt (length tvs) ts + subs = mkSubst tvs ts' + rhs' = subst subs rhs + in expandSynApp rhs' ts'' + _ -> return $ foldl' AppT t ts +expandSynApp t ts = do + t' <- expandSyn t + return $ foldl' AppT t' ts + +type Subst = Map Name Type + +mkSubst :: [TyVarBndr] -> [Type] -> Subst +mkSubst vs ts = + let vs' = map un vs + un (PlainTV v) = v + un (KindedTV v _) = v + in Map.fromList $ zip vs' ts + +subst :: Subst -> Type -> Type +subst subs (ForallT v c t) = ForallT v c $ subst subs t +subst subs t@(VarT n) = fromMaybe t $ Map.lookup n subs +subst subs (AppT t1 t2) = AppT (subst subs t1) (subst subs t2) +subst subs (SigT t k) = SigT (subst subs t) k +subst _ t = t + +------------------------------------------------------------------------------- +-- Class-specific constants +------------------------------------------------------------------------------- + +-- | A representation of which TextShow variant is being derived. +data TextShowClass = TextShow | TextShow1 | TextShow2 + deriving (Enum, Eq, Ord) + +showbPrecConstNameTable :: TextShowClass -> Name +showbPrecConstNameTable TextShow = 'showbPrecConst +showbPrecConstNameTable TextShow1 = 'showbPrecWithConst +showbPrecConstNameTable TextShow2 = 'showbPrecWith2Const + +textShowClassNameTable :: TextShowClass -> Name +textShowClassNameTable TextShow = ''TextShow +textShowClassNameTable TextShow1 = ''TextShow1 +textShowClassNameTable TextShow2 = ''TextShow2 + +showbPrecNameTable :: TextShowClass -> Name +showbPrecNameTable TextShow = 'showbPrec +showbPrecNameTable TextShow1 = 'showbPrecWith +showbPrecNameTable TextShow2 = 'showbPrecWith2 + +-- | A type-restricted version of 'const'. This is useful when generating the lambda +-- expression in 'makeShowbPrec' for a data type with only nullary constructors (since +-- the expression wouldn't depend on the precedence). For example, if you had @data +-- Nullary = Nullary@ and attempted to run @$(makeShowbPrec ''Nullary) Nullary@, simply +-- ignoring the precedence argument would cause the type signature of @$(makeShowbPrec +-- ''Nullary)@ to be @a -> Nullary -> Builder@, not @Int -> Nullary -> Builder@. +showbPrecConst :: Builder -> Int -> a -> Builder +showbPrecConst = const . const +{-# INLINE showbPrecConst #-} + +showbPrecWithConst :: Builder -> (Int -> a -> Builder) -> Int -> f a -> Builder +showbPrecWithConst = const . const . const +{-# INLINE showbPrecWithConst #-} + +showbPrecWith2Const :: Builder -> (Int -> a -> Builder) -> (Int -> b -> Builder) + -> Int -> f a b -> Builder +showbPrecWith2Const = const . const . const . const +{-# INLINE showbPrecWith2Const #-} + +------------------------------------------------------------------------------- +-- NameBase +------------------------------------------------------------------------------- + +-- | A wrapper around Name which only uses the 'nameBase' (not the entire Name) +-- to compare for equality. For example, if you had two Names a_123 and a_456, +-- they are not equal as Names, but they are equal as NameBases. +-- +-- This is useful when inspecting type variables, since a type variable in an +-- instance context may have a distinct Name from a type variable within an +-- actual constructor declaration, but we'd want to treat them as the same +-- if they have the same 'nameBase' (since that's what the programmer uses to +-- begin with). +newtype NameBase = NameBase { getName :: Name } + +getNameBase :: NameBase -> String +getNameBase = nameBase . getName + +instance Eq NameBase where + (==) = (==) `on` getNameBase + +instance Ord NameBase where + compare = compare `on` getNameBase + +instance Show NameBase where + showsPrec p = showsPrec p . getNameBase + +-- | A NameBase paired with the name of its show function. For example, in a +-- TextShow2 declaration, a list of TyVarInfos might look like [(a, 'sp1), (b, 'sp2)]. +type TyVarInfo = (NameBase, Name) + +------------------------------------------------------------------------------- +-- Assorted utilities +------------------------------------------------------------------------------- + +-- | Generate a list of fresh names with a common prefix, and numbered suffixes. +newNameList :: String -> Int -> Q [Name] +newNameList prefix n = mapM (newName . (prefix ++) . show) [1..n] + +-- | Remove any occurrences of a forall-ed type variable from a list of @TyVarInfo@s. +removeForalled :: [TyVarBndr] -> [TyVarInfo] -> [TyVarInfo] +removeForalled tvbs = filter (not . foralled tvbs) + where + foralled :: [TyVarBndr] -> TyVarInfo -> Bool + foralled tvbs' tvi = fst tvi `elem` map (NameBase . tvbName) tvbs' + +-- | Checks if a 'Name' represents a tuple type constructor (other than '()') +isNonUnitTuple :: Name -> Bool +isNonUnitTuple = isTupleString . nameBase + +-- | Parenthesize an infix constructor name if it is being applied as a prefix +-- function (e.g., data Amp a = (:&) a a) +parenInfixConName :: Name -> ShowS +parenInfixConName conName = + let conNameBase = nameBase conName + in showParen (isInfixTypeCon conNameBase) $ showString conNameBase + +-- | Extracts the name from a TyVarBndr. +tvbName :: TyVarBndr -> Name +tvbName (PlainTV name) = name +tvbName (KindedTV name _) = name + +-- | Extracts the kind from a TyVarBndr. +tvbKind :: TyVarBndr -> Kind +tvbKind (PlainTV _) = starK +tvbKind (KindedTV _ k) = k + +-- | Replace the Name of a TyVarBndr with one from a Type (if the Type has a Name). +replaceTyVarName :: TyVarBndr -> Type -> TyVarBndr +replaceTyVarName tvb (SigT t _) = replaceTyVarName tvb t +replaceTyVarName (PlainTV _) (VarT n) = PlainTV n +replaceTyVarName (KindedTV _ k) (VarT n) = KindedTV n k +replaceTyVarName tvb _ = tvb + +-- | Applies a typeclass constraint to a type. +applyClass :: Name -> Name -> Pred +#if MIN_VERSION_template_haskell(2,10,0) +applyClass con t = AppT (ConT con) (VarT t) +#else +applyClass con t = ClassP con [VarT t] +#endif + +-- | Checks to see if the last types in a data family instance can be safely eta- +-- reduced (i.e., dropped), given the other types. This checks for three conditions: +-- +-- (1) All of the dropped types are type variables +-- (2) All of the dropped types are distinct +-- (3) None of the remaining types mention any of the dropped types +canEtaReduce :: [Type] -> [Type] -> Bool +canEtaReduce remaining dropped = + all isTyVar dropped + && allDistinct nbs -- Make sure not to pass something of type [Type], since Type + -- didn't have an Ord instance until template-haskell-2.10.0.0 + && not (any (`mentionsNameBase` nbs) remaining) + where + nbs :: [NameBase] + nbs = map varTToNameBase dropped + +-- | Extract the Name from a type variable. +varTToName :: Type -> Name +varTToName (VarT n) = n +varTToName (SigT t _) = varTToName t +varTToName _ = error "Not a type variable!" + +-- | Extract the NameBase from a type variable. +varTToNameBase :: Type -> NameBase +varTToNameBase = NameBase . varTToName + +-- | Peel off a kind signature from a Type (if it has one). +unSigT :: Type -> Type +unSigT (SigT t _) = t +unSigT t = t + +-- | Is the given type a variable? +isTyVar :: Type -> Bool +isTyVar (VarT _) = True +isTyVar (SigT t _) = isTyVar t +isTyVar _ = False + +-- | Is the given type a type family constructor (and not a data family constructor)? +isTyFamily :: Type -> Q Bool +isTyFamily (ConT n) = do + info <- reify n + return $ case info of +#if MIN_VERSION_template_haskell(2,7,0) + FamilyI (FamilyD TypeFam _ _ _) _ -> True +#else + TyConI (FamilyD TypeFam _ _ _) -> True +#endif + _ -> False +isTyFamily _ = return False + +-- | Are all of the items in a list (which have an ordering) distinct? +-- +-- This uses Set (as opposed to nub) for better asymptotic time complexity. +allDistinct :: Ord a => [a] -> Bool +allDistinct = allDistinct' Set.empty + where + allDistinct' :: Ord a => Set a -> [a] -> Bool + allDistinct' uniqs (x:xs) + | x `Set.member` uniqs = False + | otherwise = allDistinct' (Set.insert x uniqs) xs + allDistinct' _ _ = True + +-- | Does the given type mention any of the NameBases in the list? +mentionsNameBase :: Type -> [NameBase] -> Bool +mentionsNameBase = go Set.empty + where + go :: Set NameBase -> Type -> [NameBase] -> Bool + go foralls (ForallT tvbs _ t) nbs = + go (foralls `Set.union` Set.fromList (map (NameBase . tvbName) tvbs)) t nbs + go foralls (AppT t1 t2) nbs = go foralls t1 nbs || go foralls t2 nbs + go foralls (SigT t _) nbs = go foralls t nbs + go foralls (VarT n) nbs = varNb `elem` nbs && not (varNb `Set.member` foralls) + where + varNb = NameBase n + go _ _ _ = False + +-- | Does an instance predicate mention any of the NameBases in the list? +predMentionsNameBase :: Pred -> [NameBase] -> Bool +#if MIN_VERSION_template_haskell(2,10,0) +predMentionsNameBase = mentionsNameBase +#else +predMentionsNameBase (ClassP _ tys) nbs = any (`mentionsNameBase` nbs) tys +predMentionsNameBase (EqualP t1 t2) nbs = mentionsNameBase t1 nbs || mentionsNameBase t2 nbs +#endif + +-- | The number of arrows that compose the spine of a kind signature +-- (e.g., (* -> *) -> k -> * has two arrows on its spine). +numKindArrows :: Kind -> Int +numKindArrows k = length (uncurryKind k) - 1 + +-- | Construct a type via curried application. +applyTy :: Type -> [Type] -> Type +applyTy = foldl' AppT + +-- | Fully applies a type constructor to its type variables. +applyTyCon :: Name -> [Type] -> Type +applyTyCon = applyTy . ConT + +-- | Split an applied type into its individual components. For example, this: +-- +-- @ +-- Either Int Char +-- @ +-- +-- would split to this: +-- +-- @ +-- [Either, Int, Char] +-- @ +unapplyTy :: Type -> NonEmpty Type +unapplyTy = NE.reverse . go + where + go :: Type -> NonEmpty Type + go (AppT t1 t2) = t2 <| go t1 + go (SigT t _) = go t + go t = t :| [] + +-- | Split a type signature by the arrows on its spine. For example, this: +-- +-- @ +-- (Int -> String) -> Char -> () +-- @ +-- +-- would split to this: +-- +-- @ +-- [Int -> String, Char, ()] +-- @ +uncurryTy :: Type -> NonEmpty Type +uncurryTy (AppT (AppT ArrowT t1) t2) = t1 <| uncurryTy t2 +uncurryTy (SigT t _) = uncurryTy t +uncurryTy t = t :| [] + +-- | Like uncurryType, except on a kind level. +uncurryKind :: Kind -> NonEmpty Kind +#if MIN_VERSION_template_haskell(2,8,0) +uncurryKind = uncurryTy +#else +uncurryKind (ArrowK k1 k2) = k1 <| uncurryKind k2 +uncurryKind k = k :| [] +#endif + +wellKinded :: [Kind] -> Bool +wellKinded = all canRealizeKindStar + +-- | Of form k1 -> k2 -> ... -> kn, where k is either a single kind variable or *. +canRealizeKindStarChain :: Kind -> Bool +canRealizeKindStarChain = all canRealizeKindStar . uncurryKind + +canRealizeKindStar :: Kind -> Bool +canRealizeKindStar k = case uncurryKind k of + k' :| [] -> case k' of +#if MIN_VERSION_template_haskell(2,8,0) + StarT -> True + (VarT _) -> True -- Kind k can be instantiated with * +#else + StarK -> True +#endif + _ -> False + _ -> False + +createKindChain :: Int -> Kind +createKindChain = go starK + where + go :: Kind -> Int -> Kind + go k !0 = k +#if MIN_VERSION_template_haskell(2,8,0) + go k !n = go (AppT (AppT ArrowT StarT) k) (n - 1) +#else + go k !n = go (ArrowK StarK k) (n - 1) +#endif + +# if MIN_VERSION_template_haskell(2,8,0) && __GLASGOW_HASKELL__ < 710 +distinctKindVars :: Kind -> Set Name +distinctKindVars (AppT k1 k2) = distinctKindVars k1 `Set.union` distinctKindVars k2 +distinctKindVars (SigT k _) = distinctKindVars k +distinctKindVars (VarT k) = Set.singleton k +distinctKindVars _ = Set.empty +#endif + +#if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 +tvbToType :: TyVarBndr -> Type +tvbToType (PlainTV n) = VarT n +tvbToType (KindedTV n k) = SigT (VarT n) k +#endif + +#if MIN_VERSION_template_haskell(2,7,0) +-- | Extracts the name of a constructor. +constructorName :: Con -> Name +constructorName (NormalC name _ ) = name +constructorName (RecC name _ ) = name +constructorName (InfixC _ name _ ) = name +constructorName (ForallC _ _ con) = constructorName con +#endif
+ src/TextShow/Text/Read.hs view
@@ -0,0 +1,78 @@+{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-| +Module: TextShow.Text.Read +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Monomorphic 'TextShow' function for 'Lexeme' (and 'Number', if using a +recent-enough version of @base@). + +/Since: 2/ +-} +module TextShow.Text.Read ( + showbLexemePrec +#if MIN_VERSION_base(4,7,0) + , showbNumberPrec +#endif + ) where + +import Data.Text.Lazy.Builder (Builder) + +import Text.Read.Lex (Lexeme(..)) +#if MIN_VERSION_base(4,7,0) +import Text.Read.Lex (Number) +#endif + +import TextShow.Classes (TextShow(showbPrec), showbUnaryWith) +#if MIN_VERSION_base(4,6,0) +import TextShow.Classes (FromStringShow(..)) +#else +import TextShow.Data.Integral () +import TextShow.Data.Ratio () +#endif +import TextShow.Data.Char () +import TextShow.Data.List () + +#include "inline.h" + +-- | Convert a 'Lexeme' to a 'Builder' with the given precedence. +-- +-- /Since: 2/ +showbLexemePrec :: Int -> Lexeme -> Builder +showbLexemePrec p (Char c) = showbUnaryWith showbPrec "Char" p c +showbLexemePrec p (String s) = showbUnaryWith showbPrec "String" p s +showbLexemePrec p (Punc pun) = showbUnaryWith showbPrec "Punc" p pun +showbLexemePrec p (Ident i) = showbUnaryWith showbPrec "Ident" p i +showbLexemePrec p (Symbol s) = showbUnaryWith showbPrec "Symbol" p s +#if MIN_VERSION_base(4,6,0) +showbLexemePrec p (Number n) = showbUnaryWith showbPrec "Number" p $ FromStringShow n +#else +showbLexemePrec p (Int i) = showbUnaryWith showbPrec "Int" p i +showbLexemePrec p (Rat r) = showbUnaryWith showbPrec "Rat" p r +#endif +showbLexemePrec _ EOF = "EOF" + +#if MIN_VERSION_base(4,7,0) +-- | Convert a 'Number' to a 'Builder' with the given precedence. +-- This function is only available with @base-4.7.0.0@ or later. +-- +-- /Since: 2/ +showbNumberPrec :: Int -> Number -> Builder +showbNumberPrec p = showbPrec p . FromStringShow +{-# INLINE showbNumberPrec #-} +#endif + +instance TextShow Lexeme where + showbPrec = showbLexemePrec + INLINE_INST_FUN(showbPrec) + +#if MIN_VERSION_base(4,7,0) +instance TextShow Number where + showbPrec = showbNumberPrec + {-# INLINE showbPrec #-} +#endif
+ src/TextShow/Utils.hs view
@@ -0,0 +1,80 @@+{-# LANGUAGE MagicHash #-} + +{-| +Module: TextShow.Utils +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +Miscellaneous utility functions. +-} +module TextShow.Utils where + +import Data.Int (Int64) +import Data.Text (Text) +import Data.Monoid.Compat ((<>)) +import Data.Text.Lazy (length, toStrict, unpack) +import Data.Text.Lazy.Builder (Builder, singleton, toLazyText) + +import GHC.Exts (Char(C#), Int(I#)) +import GHC.Prim ((+#), chr#, ord#) + +import Prelude () +import Prelude.Compat hiding (length) + +-- | Unsafe conversion for decimal digits. +i2d :: Int -> Char +i2d (I# i#) = C# (chr# (ord# '0'# +# i#)) +{-# INLINE i2d #-} + +-- | Checks if a 'String' names a valid Haskell infix type constructor (i.e., does +-- it begin with a colon?). +isInfixTypeCon :: String -> Bool +isInfixTypeCon (':':_) = True +isInfixTypeCon _ = False +{-# INLINE isInfixTypeCon #-} + +-- | Checks if a 'String' represents a tuple (other than '()') +isTupleString :: String -> Bool +isTupleString ('(':',':_) = True +isTupleString _ = False +{-# INLINE isTupleString #-} + +-- | Computes the length of a 'Builder'. +-- +-- /Since: 2/ +lengthB :: Builder -> Int64 +lengthB = length . toLazyText +{-# INLINE lengthB #-} + +-- | Convert a 'Builder' to a 'String' (without surrounding it with double quotes, +-- as 'show' would). +-- +-- /Since: 2/ +toString :: Builder -> String +toString = unpack . toLazyText +{-# INLINE toString #-} + +-- | Convert a 'Builder' to a strict 'Text'. +-- +-- /Since: 2/ +toText :: Builder -> Text +toText = toStrict . toLazyText +{-# INLINE toText #-} + +-- | Merges several 'Builder's, separating them by newlines. +-- +-- /Since: 2/ +unlinesB :: [Builder] -> Builder +unlinesB (b:bs) = b <> singleton '\n' <> unlinesB bs +unlinesB [] = mempty + +-- | Merges several 'Builder's, separating them by spaces. +-- +-- /Since: 2/ +unwordsB :: [Builder] -> Builder +unwordsB (b:bs@(_:_)) = b <> singleton ' ' <> unwordsB bs +unwordsB [b] = b +unwordsB [] = mempty
tests/Derived/DataFamilies.hs view
@@ -44,16 +44,15 @@ import GHC.Show (appPrec, appPrec1, showSpace) import Prelude () -import Prelude.Compat hiding (Show) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..), oneof) -import Text.Show as S #if MIN_VERSION_template_haskell(2,7,0) -import Text.Show.Text.TH (deriveShow, deriveShow1, deriveShow2) +import TextShow.TH (deriveTextShow, deriveTextShow1, deriveTextShow2) #endif -import TransformersCompat as S +import TransformersCompat (Show1(..), Show2(..)) ------------------------------------------------------------------------------- @@ -67,7 +66,7 @@ data instance NotAllShow () () () d = NASNoShow data instance NotAllShow Int b c d = NASShow1 c b | NASShow2 d - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -81,9 +80,9 @@ , NASShow2 <$> arbitrary ] -instance (S.Show b, S.Show c) => S.Show1 (NotAllShow Int b c) where +instance (Show b, Show c) => Show1 (NotAllShow Int b c) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show b => S.Show2 (NotAllShow Int b) where +instance Show b => Show2 (NotAllShow Int b) where showsPrecWith2 sp1 _ p (NASShow1 c b) = showParen (p > appPrec) $ showString "NASShow1 " . sp1 appPrec1 c . showSpace @@ -93,9 +92,9 @@ . sp2 appPrec1 d #if MIN_VERSION_template_haskell(2,7,0) -$(deriveShow 'NASShow1) -$(deriveShow1 'NASShow2) -$(deriveShow2 'NASShow1) +$(deriveTextShow 'NASShow1) +$(deriveTextShow1 'NASShow2) +$(deriveTextShow2 'NASShow1) #endif ------------------------------------------------------------------------------- @@ -106,7 +105,7 @@ instance NullaryClass where newtype NullaryData = NullaryCon Int - deriving (Arbitrary, S.Show, Generic) + deriving (Arbitrary, Show, Generic) -$(deriveShow 'NullaryCon) +$(deriveTextShow 'NullaryCon) # endif
tests/Derived/DatatypeContexts.hs view
@@ -19,20 +19,19 @@ import GHC.Show (appPrec, appPrec1, showSpace) import Prelude () -import Prelude.Compat hiding (Show) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..)) -import Text.Show as S -import Text.Show.Text as T -import Text.Show.Text.TH (mkShowbPrec, mkShowbPrecWith, mkShowbPrecWith2) +import TextShow (TextShow(..), TextShow1(..), TextShow2(..)) +import TextShow.TH (makeShowbPrec, makeShowbPrecWith, makeShowbPrecWith2) -import TransformersCompat as S +import TransformersCompat (Show1(..), Show2(..)) ------------------------------------------------------------------------------- data Ord a => TyCon a b c = TyCon a b c - deriving S.Show + deriving Show ------------------------------------------------------------------------------- @@ -44,7 +43,7 @@ #endif data instance Ord a => TyFamily a b c = TyFamily a b c - deriving S.Show + deriving Show ------------------------------------------------------------------------------- @@ -56,19 +55,19 @@ ------------------------------------------------------------------------------- -instance (Ord a, S.Show a, S.Show b) => S.Show1 (TyCon a b) where +instance (Ord a, Show a, Show b) => Show1 (TyCon a b) where showsPrecWith = showsPrecWith2 showsPrec -instance (Ord a, S.Show a) => S.Show2 (TyCon a) where +instance (Ord a, Show a) => Show2 (TyCon a) where showsPrecWith2 sp1 sp2 p (TyCon a b c) = showsThree sp1 sp2 "TyCon" p a b c -instance (Ord a, S.Show a, S.Show b) => S.Show1 (TyFamily a b) where +instance (Ord a, Show a, Show b) => Show1 (TyFamily a b) where showsPrecWith = showsPrecWith2 showsPrec -instance (Ord a, S.Show a) => S.Show2 (TyFamily a) where +instance (Ord a, Show a) => Show2 (TyFamily a) where showsPrecWith2 sp1 sp2 p (TyFamily a b c) = showsThree sp1 sp2 "TyFamily" p a b c -showsThree :: S.Show a +showsThree :: Show a => (Int -> b -> ShowS) -> (Int -> c -> ShowS) -> String -> Int -> a -> b -> c -> ShowS showsThree sp1 sp2 name p a b c = showParen (p > appPrec) $ @@ -81,18 +80,18 @@ $(return []) -instance (Ord a, T.Show a, T.Show b, T.Show c) => T.Show (TyCon a b c) where - showbPrec = $(mkShowbPrec ''TyCon) -instance (Ord a, T.Show a, T.Show b) => T.Show1 (TyCon a b) where - showbPrecWith = $(mkShowbPrecWith ''TyCon) -instance (Ord a, T.Show a) => T.Show2 (TyCon a) where - showbPrecWith2 = $(mkShowbPrecWith2 ''TyCon) +instance (Ord a, TextShow a, TextShow b, TextShow c) => TextShow (TyCon a b c) where + showbPrec = $(makeShowbPrec ''TyCon) +instance (Ord a, TextShow a, TextShow b) => TextShow1 (TyCon a b) where + showbPrecWith = $(makeShowbPrecWith ''TyCon) +instance (Ord a, TextShow a) => TextShow2 (TyCon a) where + showbPrecWith2 = $(makeShowbPrecWith2 ''TyCon) #if MIN_VERSION_template_haskell(2,7,0) -instance (Ord a, T.Show a, T.Show b, T.Show c) => T.Show (TyFamily a b c) where - showbPrec = $(mkShowbPrec 'TyFamily) -instance (Ord a, T.Show a, T.Show b) => T.Show1 (TyFamily a b) where - showbPrecWith = $(mkShowbPrecWith 'TyFamily) -instance (Ord a, T.Show a) => T.Show2 (TyFamily a) where - showbPrecWith2 = $(mkShowbPrecWith2 'TyFamily) +instance (Ord a, TextShow a, TextShow b, TextShow c) => TextShow (TyFamily a b c) where + showbPrec = $(makeShowbPrec 'TyFamily) +instance (Ord a, TextShow a, TextShow b) => TextShow1 (TyFamily a b) where + showbPrecWith = $(makeShowbPrecWith 'TyFamily) +instance (Ord a, TextShow a) => TextShow2 (TyFamily a) where + showbPrecWith2 = $(makeShowbPrecWith2 'TyFamily) #endif
tests/Derived/ExistentialQuantification.hs view
@@ -20,15 +20,14 @@ import GHC.Show (appPrec, appPrec1, showSpace) import Prelude () -import Prelude.Compat hiding (Show) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..), Gen, oneof) -import Text.Show as S (Show) -import Text.Show.Text as T (Show) -import Text.Show.Text.TH (deriveShow, deriveShow1, deriveShow2) +import TextShow (TextShow) +import TextShow.TH (deriveTextShow, deriveTextShow1, deriveTextShow2) -import TransformersCompat as S (Show1(..), Show2(..), showsBinaryWith) +import TransformersCompat (Show1(..), Show2(..), showsBinaryWith) ------------------------------------------------------------------------------- @@ -45,8 +44,8 @@ -> TyCon Int z Int z TyConForalls :: forall p q r s t u. - (Arbitrary p, S.Show p, T.Show p, - Arbitrary q, S.Show q, T.Show q) + (Arbitrary p, Show p, TextShow p, + Arbitrary q, Show q, TextShow q) => p -> q -> u -> t -> TyCon r s t u @@ -72,8 +71,8 @@ -> TyFamily Int z Int z TyFamilyForalls :: forall p q r s t u. - (Arbitrary p, S.Show p, T.Show p, - Arbitrary q, S.Show q, T.Show q) + (Arbitrary p, Show p, TextShow p, + Arbitrary q, Show q, TextShow q) => p -> q -> u -> t -> TyFamily r s t u @@ -97,10 +96,10 @@ ------------------------------------------------------------------------------- -deriving instance (S.Show a, S.Show b, S.Show c, S.Show d) => S.Show (TyCon a b c d) -instance (S.Show a, S.Show b, S.Show c) => S.Show1 (TyCon a b c) where +deriving instance (Show a, Show b, Show c, Show d) => Show (TyCon a b c d) +instance (Show a, Show b, Show c) => Show1 (TyCon a b c) where showsPrecWith = showsPrecWith2 showsPrec -instance (S.Show a, S.Show b) => S.Show2 (TyCon a b) where +instance (Show a, Show b) => Show2 (TyCon a b) where showsPrecWith2 sp1 sp2 p (TyConClassConstraints a b c d) = showsFour sp1 sp2 "TyConClassConstraints" p a b c d showsPrecWith2 sp1 sp2 p (TyConEqualityConstraints a b c d) = @@ -110,10 +109,10 @@ showsPrecWith2 sp1 sp2 p (TyConForalls p' q d c) = showsFour sp2 sp1 "TyConForalls" p p' q d c -deriving instance (S.Show a, S.Show b, S.Show c, S.Show d) => S.Show (TyFamily a b c d) -instance (S.Show a, S.Show b, S.Show c) => S.Show1 (TyFamily a b c) where +deriving instance (Show a, Show b, Show c, Show d) => Show (TyFamily a b c d) +instance (Show a, Show b, Show c) => Show1 (TyFamily a b c) where showsPrecWith = showsPrecWith2 showsPrec -instance (S.Show a, S.Show b) => S.Show2 (TyFamily a b) where +instance (Show a, Show b) => Show2 (TyFamily a b) where showsPrecWith2 sp1 sp2 p (TyFamilyClassConstraints a b c d) = showsFour sp1 sp2 "TyFamilyClassConstraints" p a b c d showsPrecWith2 sp1 sp2 p (TyFamilyEqualityConstraints a b c d) = @@ -123,7 +122,7 @@ showsPrecWith2 sp1 sp2 p (TyFamilyForalls p' q d c) = showsFour sp2 sp1 "TyFamilyForalls" p p' q d c -showsFour :: (S.Show a, S.Show b) +showsFour :: (Show a, Show b) => (Int -> c -> ShowS) -> (Int -> d -> ShowS) -> String -> Int -> a -> b -> c -> d -> ShowS showsFour sp1 sp2 name p a b c d = showParen (p > appPrec) $ @@ -135,12 +134,12 @@ ------------------------------------------------------------------------------- -$(deriveShow ''TyCon) -$(deriveShow1 ''TyCon) -$(deriveShow2 ''TyCon) +$(deriveTextShow ''TyCon) +$(deriveTextShow1 ''TyCon) +$(deriveTextShow2 ''TyCon) #if MIN_VERSION_template_haskell(2,7,0) -$(deriveShow 'TyFamilyClassConstraints) -$(deriveShow1 'TyFamilyEqualityConstraints) -$(deriveShow2 'TyFamilyTypeRefinement) +$(deriveTextShow 'TyFamilyClassConstraints) +$(deriveTextShow1 'TyFamilyEqualityConstraints) +$(deriveTextShow2 'TyFamilyTypeRefinement) #endif
tests/Derived/Infix.hs view
@@ -35,14 +35,13 @@ import GHC.Show (appPrec, appPrec1, showSpace) import Prelude () -import Prelude.Compat hiding (Show(..)) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..), oneof) -import Text.Show as S (Show(..)) -import Text.Show.Text.TH (deriveShow, deriveShow1, deriveShow2) +import TextShow.TH (deriveTextShow, deriveTextShow1, deriveTextShow2) -import TransformersCompat as S (Show1(..), Show2(..), showsBinaryWith) +import TransformersCompat (Show1(..), Show2(..), showsBinaryWith) ------------------------------------------------------------------------------- @@ -52,7 +51,7 @@ data TyConPlain a b = (:!:) a b | a :@: b | a `TyConPlain` b - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 702 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -69,7 +68,7 @@ (:..) :: e -> f -> TyConGADT e f (:...) :: g -> h -> Int -> TyConGADT g h (:....) :: { tcg1 :: i, tcg2 :: j } -> TyConGADT i j - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -93,7 +92,7 @@ data instance TyFamilyPlain a b = (:#:) a b | a :$: b | a `TyFamilyPlain` b - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -117,7 +116,7 @@ (:**) :: e -> f -> TyFamilyGADT e f (:***) :: g -> h -> Int -> TyFamilyGADT g h (:****) :: { tfg1 :: i, tfg2 :: j } -> TyFamilyGADT i j - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -152,9 +151,9 @@ ------------------------------------------------------------------------------- -instance S.Show a => S.Show1 (TyConPlain a) where +instance Show a => Show1 (TyConPlain a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyConPlain where +instance Show2 TyConPlain where showsPrecWith2 sp1 sp2 p (a :!: b) = showsBinaryWith sp1 sp2 "(:!:)" p a b showsPrecWith2 sp1 sp2 p (a :@: b) = @@ -162,9 +161,9 @@ showsPrecWith2 sp1 sp2 p (TyConPlain a b) = showsInfix sp1 sp2 "`TyConPlain`" p 5 a b -instance S.Show a => S.Show1 (TyConGADT a) where +instance Show a => Show1 (TyConGADT a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyConGADT where +instance Show2 TyConGADT where showsPrecWith2 sp1 sp2 p (a :. b) = showsInfix sp1 sp2 ":." p 1 a b showsPrecWith2 sp1 sp2 p (a :.. b) = @@ -174,9 +173,9 @@ showsPrecWith2 sp1 sp2 p (a :.... b) = showsBinaryWith sp1 sp2 "(:....)" p a b -instance S.Show a => S.Show1 (TyFamilyPlain a) where +instance Show a => Show1 (TyFamilyPlain a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyFamilyPlain where +instance Show2 TyFamilyPlain where showsPrecWith2 sp1 sp2 p (a :#: b) = showsBinaryWith sp1 sp2 "(:#:)" p a b showsPrecWith2 sp1 sp2 p (a :$: b) = @@ -184,9 +183,9 @@ showsPrecWith2 sp1 sp2 p (TyFamilyPlain a b) = showsInfix sp1 sp2 "`TyFamilyPlain`" p 5 a b -instance S.Show a => S.Show1 (TyFamilyGADT a) where +instance Show a => Show1 (TyFamilyGADT a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyFamilyGADT where +instance Show2 TyFamilyGADT where showsPrecWith2 sp1 sp2 p (a :* b) = showsInfix sp1 sp2 ":*" p 1 a b showsPrecWith2 sp1 sp2 p (a :** b) = @@ -213,20 +212,20 @@ ------------------------------------------------------------------------------- -$(deriveShow ''TyConPlain) -$(deriveShow1 ''TyConPlain) -$(deriveShow2 ''TyConPlain) +$(deriveTextShow ''TyConPlain) +$(deriveTextShow1 ''TyConPlain) +$(deriveTextShow2 ''TyConPlain) -$(deriveShow ''TyConGADT) -$(deriveShow1 ''TyConGADT) -$(deriveShow2 ''TyConGADT) +$(deriveTextShow ''TyConGADT) +$(deriveTextShow1 ''TyConGADT) +$(deriveTextShow2 ''TyConGADT) #if MIN_VERSION_template_haskell(2,7,0) -$(deriveShow '(:#:)) -$(deriveShow1 '(:$:)) -$(deriveShow2 'TyFamilyPlain) +$(deriveTextShow '(:#:)) +$(deriveTextShow1 '(:$:)) +$(deriveTextShow2 'TyFamilyPlain) -$(deriveShow '(:*)) -$(deriveShow1 '(:***)) -$(deriveShow2 '(:****)) +$(deriveTextShow '(:*)) +$(deriveTextShow1 '(:***)) +$(deriveTextShow2 '(:****)) #endif
tests/Derived/MagicHash.hs view
@@ -18,12 +18,11 @@ import GHC.Exts import Prelude () -import Prelude.Compat hiding (Show) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..)) -import Text.Show as S (Show) -import Text.Show.Text.TH (deriveShow) +import TextShow.TH (deriveTextShow) ------------------------------------------------------------------------------- @@ -33,8 +32,8 @@ , tcDouble# :: Double# , tcChar# :: Char# , tcWord# :: Word# -} deriving S.Show -$(deriveShow ''TyCon#) +} deriving Show +$(deriveTextShow ''TyCon#) ------------------------------------------------------------------------------- @@ -45,9 +44,9 @@ , tfDouble# :: Double# , tfChar# :: Char# , tfWord# :: Word# -} deriving S.Show +} deriving Show #if MIN_VERSION_template_haskell(2,7,0) -$(deriveShow 'TyFamily#) +$(deriveTextShow 'TyFamily#) #endif -------------------------------------------------------------------------------
tests/Derived/PolyKinds.hs view
@@ -27,8 +27,10 @@ module Derived.PolyKinds ( TyConCompose(..) , TyConProxy(..) + , TyConReallyHighKinds , TyFamilyCompose(..) , TyFamilyProxy(..) + , TyFamilyReallyHighKinds(..) ) where #include "generic.h" @@ -43,15 +45,13 @@ #endif import GHC.Show (appPrec, appPrec1, showSpace) -import Prelude hiding (Show) - import Test.QuickCheck (Arbitrary) -import Text.Show as S (Show) -import Text.Show.Text as T (Show(..), Show1(..)) -import Text.Show.Text.TH (deriveShow2, mkShowbPrec, mkShowbPrecWith) +import TextShow (TextShow(..), TextShow1(..), TextShow2(..)) +import TextShow.TH (deriveTextShow2, makeShowbPrec, + makeShowbPrecWith, makeShowbPrecWith2) -import TransformersCompat as S (Show1(..), Show2(..)) +import TransformersCompat (Show1(..), Show2(..), showsUnaryWith) ------------------------------------------------------------------------------- @@ -70,14 +70,14 @@ ) => Generic1 (TyConCompose f g h j k a) # endif -deriving instance S.Show (f (g (j a) (k a)) (h (j a) (k b))) => - S.Show (TyConCompose f g h j k a b) +deriving instance Show (f (g (j a) (k a)) (h (j a) (k b))) => + Show (TyConCompose f g h j k a b) ------------------------------------------------------------------------------- newtype TyConProxy a b = TyConProxy () deriving ( Arbitrary - , S.Show + , Show #if __GLASGOW_HASKELL__ >= 702 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -88,33 +88,47 @@ ------------------------------------------------------------------------------- +newtype TyConReallyHighKinds f a b c d e = TyConReallyHighKinds (f a b c d e) + deriving ( Arbitrary + , Show +#if __GLASGOW_HASKELL__ >= 702 + , Generic +# if defined(__LANGUAGE_DERIVE_GENERIC1__) + , Generic1 +# endif +#endif + ) + +------------------------------------------------------------------------------- + data family TyFamilyCompose #if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 - (f :: k1 -> k2 -> *) - (g :: k3 -> k4 -> k1) - (h :: k3 -> k4 -> k2) - (j :: k5 -> k3) - (k :: k5 -> k4) - (a :: k5) - (b :: k5) + (f :: k1 -> k2 -> *) + (g :: k3 -> k4 -> k1) + (h :: k3 -> k4 -> k2) + (j :: k5 -> k3) + (k :: k5 -> k4) + (a :: k5) + (b :: k5) #elif __GLASGOW_HASKELL__ >= 706 - (t :: k1 -> k2 -> *) - (u :: k3 -> k4 -> k1) - (v :: k3 -> k4 -> k2) - (w :: k5 -> k3) - (x :: k5 -> k4) - (y :: k5) - (z :: k5) + (t :: k1 -> k2 -> *) + (u :: k3 -> k4 -> k1) + (v :: k3 -> k4 -> k2) + (w :: k5 -> k3) + (x :: k5 -> k4) + (y :: k5) + (z :: k5) #else - (t :: * -> * -> *) - (u :: * -> * -> *) - (v :: * -> * -> *) - (w :: * -> *) - (x :: * -> *) - (y :: *) - (z :: *) + (t :: * -> * -> *) + (u :: * -> * -> *) + (v :: * -> * -> *) + (w :: * -> *) + (x :: * -> *) + (y :: *) + (z :: *) #endif - :: * + :: * + newtype instance TyFamilyCompose f g h j k a b = TyFamilyCompose (f (g (j a) (k a)) (h (j a) (k b))) #if __GLASGOW_HASKELL__ >= 706 @@ -130,24 +144,24 @@ ) => Generic1 (TyFamilyCompose f g h j k a) # endif -deriving instance S.Show (f (g (j a) (k a)) (h (j a) (k b))) => - S.Show (TyFamilyCompose f g h j k a b) +deriving instance Show (f (g (j a) (k a)) (h (j a) (k b))) => + Show (TyFamilyCompose f g h j k a b) ------------------------------------------------------------------------------- data family TyFamilyProxy #if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 - (a :: k1) (b :: k2) :: * + (a :: k1) (b :: k2) #elif __GLASGOW_HASKELL__ >= 706 - (x :: k1) (y :: k2) :: * + (x :: k1) (y :: k2) #else - (x :: *) (y :: *) :: * + (x :: *) (y :: *) #endif - + :: * newtype instance TyFamilyProxy a b = TyFamilyProxy () deriving ( Arbitrary - , S.Show + , Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -158,46 +172,99 @@ ------------------------------------------------------------------------------- -instance (S.Show1 (f (g (j a) (k a))), S.Show1 (h (j a)), S.Show1 k) => - S.Show1 (TyConCompose f g h j k a) where +data family TyFamilyReallyHighKinds +#if __GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710 + (f :: k1 -> k2 -> k3 -> k4 -> k5 -> *) + (a :: k1) + (b :: k2) + (c :: k3) + (d :: k4) + (e :: k5) +#elif __GLASGOW_HASKELL__ >= 706 + (g :: k1 -> k2 -> k3 -> k4 -> k5 -> *) + (v :: k1) + (w :: k2) + (x :: k3) + (y :: k4) + (z :: k5) +#else + (g :: * -> * -> * -> * -> * -> *) + (v :: *) + (w :: *) + (x :: *) + (y :: *) + (z :: *) +#endif + :: * + +newtype instance TyFamilyReallyHighKinds f a b c d e = + TyFamilyReallyHighKinds (f a b c d e) + deriving ( Arbitrary + , Show +#if __GLASGOW_HASKELL__ >= 706 + , Generic +# if defined(__LANGUAGE_DERIVE_GENERIC1__) + , Generic1 +# endif +#endif + ) + +------------------------------------------------------------------------------- + +instance (Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) => + Show1 (TyConCompose f g h j k a) where showsPrecWith sp p (TyConCompose x) = showsPrecCompose sp "TyConCompose" p x -instance (S.Show2 f, S.Show2 g, S.Show2 h, S.Show1 j, S.Show1 k) => - S.Show2 (TyConCompose f g h j k) where +instance (Show2 f, Show2 g, Show2 h, Show1 j, Show1 k) => + Show2 (TyConCompose f g h j k) where showsPrecWith2 sp1 sp2 p (TyConCompose x) = showsPrecCompose2 sp1 sp2 "TyConCompose" p x -instance S.Show1 (TyConProxy (a :: *)) where +instance Show1 (TyConProxy (a :: *)) where showsPrecWith = showsPrecWith2 undefined -instance S.Show2 TyConProxy where +instance Show2 TyConProxy where showsPrecWith2 _ _ p (TyConProxy x) = showParen (p > appPrec) $ showString "TyConProxy " . showsPrec appPrec1 x -instance (S.Show1 (f (g (j a) (k a))), S.Show1 (h (j a)), S.Show1 k) => - S.Show1 (TyFamilyCompose f g h j k a) where +instance Show1 (f a b c d) => Show1 (TyConReallyHighKinds f a b c d) where + showsPrecWith sp p (TyConReallyHighKinds x) = + showsUnaryWith (showsPrecWith sp) "TyConReallyHighKinds" p x +instance Show2 (f a b c) => Show2 (TyConReallyHighKinds f a b c) where + showsPrecWith2 sp1 sp2 p (TyConReallyHighKinds x) = + showsUnaryWith (showsPrecWith2 sp1 sp2) "TyConReallyHighKinds" p x + +instance (Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) => + Show1 (TyFamilyCompose f g h j k a) where showsPrecWith sp p (TyFamilyCompose x) = showsPrecCompose sp "TyFamilyCompose" p x -instance (S.Show2 f, S.Show2 g, S.Show2 h, S.Show1 j, S.Show1 k) => - S.Show2 (TyFamilyCompose f g h j k) where +instance (Show2 f, Show2 g, Show2 h, Show1 j, Show1 k) => + Show2 (TyFamilyCompose f g h j k) where showsPrecWith2 sp1 sp2 p (TyFamilyCompose x) = showsPrecCompose2 sp1 sp2 "TyFamilyCompose" p x -instance S.Show1 (TyFamilyProxy (a :: *)) where +instance Show1 (TyFamilyProxy (a :: *)) where showsPrecWith = showsPrecWith2 undefined -instance S.Show2 TyFamilyProxy where +instance Show2 TyFamilyProxy where showsPrecWith2 _ _ p (TyFamilyProxy x) = showParen (p > appPrec) $ showString "TyFamilyProxy " . showsPrec appPrec1 x -showsPrecCompose :: (S.Show1 (f (g (j a) (k a))), S.Show1 (h (j a)), S.Show1 k) +instance Show1 (f a b c d) => Show1 (TyFamilyReallyHighKinds f a b c d) where + showsPrecWith sp p (TyFamilyReallyHighKinds x) = + showsUnaryWith (showsPrecWith sp) "TyFamilyReallyHighKinds" p x +instance Show2 (f a b c) => Show2 (TyFamilyReallyHighKinds f a b c) where + showsPrecWith2 sp1 sp2 p (TyFamilyReallyHighKinds x) = + showsUnaryWith (showsPrecWith2 sp1 sp2) "TyFamilyReallyHighKinds" p x + +showsPrecCompose :: (Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) => (Int -> b -> ShowS) -> String -> Int -> f (g (j a) (k a)) (h (j a) (k b)) -> ShowS showsPrecCompose sp name p x = showParen (p > appPrec) $ showString name . showSpace . showsPrecWith (showsPrecWith (showsPrecWith sp)) appPrec1 x -showsPrecCompose2 :: (S.Show2 f, S.Show2 g, S.Show2 h, S.Show1 j, S.Show1 k) +showsPrecCompose2 :: (Show2 f, Show2 g, Show2 h, Show1 j, Show1 k) => (Int -> a -> ShowS) -> (Int -> b -> ShowS) -> String -> Int -> f (g (j a) (k a)) (h (j a) (k b)) -> ShowS showsPrecCompose2 sp1 sp2 name p x = showParen (p > appPrec) $ @@ -210,37 +277,52 @@ $(return []) -instance T.Show (f (g (j a) (k a)) (h (j a) (k b))) => - T.Show (TyConCompose f g h j k a b) where - showbPrec = $(mkShowbPrec ''TyConCompose) -instance (T.Show1 (f (g (j a) (k a))), T.Show1 (h (j a)), T.Show1 k) => - T.Show1 (TyConCompose f g h j k a) where - showbPrecWith = $(mkShowbPrecWith ''TyConCompose) -$(deriveShow2 ''TyConCompose) +instance TextShow (f (g (j a) (k a)) (h (j a) (k b))) => + TextShow (TyConCompose f g h j k a b) where + showbPrec = $(makeShowbPrec ''TyConCompose) +instance (TextShow1 (f (g (j a) (k a))), TextShow1 (h (j a)), TextShow1 k) => + TextShow1 (TyConCompose f g h j k a) where + showbPrecWith = $(makeShowbPrecWith ''TyConCompose) +$(deriveTextShow2 ''TyConCompose) -instance T.Show (TyConProxy a b) where - showbPrec = $(mkShowbPrec ''TyConProxy) -instance T.Show1 (TyConProxy a) where - showbPrecWith = $(mkShowbPrecWith ''TyConProxy) -$(deriveShow2 ''TyConProxy) +instance TextShow (TyConProxy a b) where + showbPrec = $(makeShowbPrec ''TyConProxy) +instance TextShow1 (TyConProxy a) where + showbPrecWith = $(makeShowbPrecWith ''TyConProxy) +$(deriveTextShow2 ''TyConProxy) +instance TextShow (f a b c d e) => TextShow (TyConReallyHighKinds f a b c d e) where + showbPrec = $(makeShowbPrec ''TyConReallyHighKinds) +instance TextShow1 (f a b c d) => TextShow1 (TyConReallyHighKinds f a b c d) where + showbPrecWith = $(makeShowbPrecWith ''TyConReallyHighKinds) +instance TextShow2 (f a b c) => TextShow2 (TyConReallyHighKinds f a b c) where + showbPrecWith2 = $(makeShowbPrecWith2 ''TyConReallyHighKinds) + #if MIN_VERSION_template_haskell(2,7,0) -instance T.Show (f (g (j a) (k a)) (h (j a) (k b))) => - T.Show (TyFamilyCompose f g h j k a b) where - showbPrec = $(mkShowbPrec 'TyFamilyCompose) -instance (T.Show1 (f (g (j a) (k a))), T.Show1 (h (j a)), T.Show1 k) => - T.Show1 (TyFamilyCompose f g h j k a) where - showbPrecWith = $(mkShowbPrecWith 'TyFamilyCompose) -$(deriveShow2 'TyFamilyCompose) +instance TextShow (f (g (j a) (k a)) (h (j a) (k b))) => + TextShow (TyFamilyCompose f g h j k a b) where + showbPrec = $(makeShowbPrec 'TyFamilyCompose) +instance (TextShow1 (f (g (j a) (k a))), TextShow1 (h (j a)), TextShow1 k) => + TextShow1 (TyFamilyCompose f g h j k a) where + showbPrecWith = $(makeShowbPrecWith 'TyFamilyCompose) +$(deriveTextShow2 'TyFamilyCompose) -instance T.Show (TyFamilyProxy a b) where - showbPrec = $(mkShowbPrec 'TyFamilyProxy) -instance T.Show1 (TyFamilyProxy a) where - showbPrecWith = $(mkShowbPrecWith 'TyFamilyProxy) -$(deriveShow2 'TyFamilyProxy) +instance TextShow (TyFamilyProxy a b) where + showbPrec = $(makeShowbPrec 'TyFamilyProxy) +instance TextShow1 (TyFamilyProxy a) where + showbPrecWith = $(makeShowbPrecWith 'TyFamilyProxy) +$(deriveTextShow2 'TyFamilyProxy) + +instance TextShow (f a b c d e) => TextShow (TyFamilyReallyHighKinds f a b c d e) where + showbPrec = $(makeShowbPrec 'TyFamilyReallyHighKinds) +instance TextShow1 (f a b c d) => TextShow1 (TyFamilyReallyHighKinds f a b c d) where + showbPrecWith = $(makeShowbPrecWith 'TyFamilyReallyHighKinds) +instance TextShow2 (f a b c) => TextShow2 (TyFamilyReallyHighKinds f a b c) where + showbPrecWith2 = $(makeShowbPrecWith2 'TyFamilyReallyHighKinds) #endif #if __GLASGOW_HASKELL__ < 702 $(Generics.deriveAll ''TyConCompose) $(Generics.deriveAll ''TyConProxy) +$(Generics.deriveAll ''TyConReallyHighKinds) #endif
tests/Derived/RankNTypes.hs view
@@ -21,23 +21,22 @@ module Derived.RankNTypes (TyCon(..), TyFamily(..)) where import Prelude () -import Prelude.Compat hiding (Show(..)) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..)) -import Text.Show as S (Show(..)) -import Text.Show.Text as T (Show(..), Show1(..), Show2(..)) -import Text.Show.Text.TH (deriveShow, deriveShow1, deriveShow2, - mkShowbPrec, mkShowbPrecWith, mkShowbPrecWith2) +import TextShow (Show(..), Show1(..), Show2(..)) +import TextShow.TH (deriveTextShow, deriveTextShow1, deriveTextShow2, + makeShowbPrec, makeShowbPrecWith, makeShowbPrecWith2) -import TransformersCompat as S (Show1(..), Show2(..), showsUnaryWith, showsBinaryWith) +import TransformersCompat (Show1(..), Show2(..), showsUnaryWith, showsBinaryWith) ------------------------------------------------------------------------------- data TyCon a b = TyCon (forall a. Tagged2 a Int b) (forall b. Tagged2 b a a) -deriving instance (S.Show a, S.Show b) => S.Show (TyCon a b) +deriving instance (Show a, Show b) => Show (TyCon a b) ------------------------------------------------------------------------------- @@ -51,12 +50,12 @@ data instance TyFamily a b = TyFamily (forall a. Tagged2 a Int b) (forall b. Tagged2 b a a) -deriving instance (S.Show a, S.Show b) => S.Show (TyFamily a b) +deriving instance (Show a, Show b) => Show (TyFamily a b) ------------------------------------------------------------------------------- newtype Tagged2 s t c = Tagged2 c - deriving S.Show + deriving Show ------------------------------------------------------------------------------- @@ -76,15 +75,15 @@ ------------------------------------------------------------------------------- -instance S.Show a => S.Show1 (TyCon a) where +instance Show a => Show1 (TyCon a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyCon where +instance Show2 TyCon where showsPrecWith2 sp1 sp2 p (TyCon b a) = showsForall sp1 sp2 "TyCon" p b a -instance S.Show a => S.Show1 (TyFamily a) where +instance Show a => Show1 (TyFamily a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyFamily where +instance Show2 TyFamily where showsPrecWith2 sp1 sp2 p (TyFamily b a) = showsForall sp1 sp2 "TyFamily" p b a @@ -114,17 +113,17 @@ $(return []) -instance S.Show1 (Tagged2 s t) where +instance TextShow1 (Tagged2 s t) where showsPrecWith sp p (Tagged2 b) = showsUnaryWith sp "Tagged2" p b -instance S.Show2 (Tagged2 s) where +instance TextShow2 (Tagged2 s) where showsPrecWith2 _ = showsPrecWith -instance T.Show c => T.Show (Tagged2 s t c) where - showbPrec = $(mkShowbPrec ''Tagged2) +instance TextShow c => TextShow (Tagged2 s t c) where + showbPrec = $(makeShowbPrec ''Tagged2) -instance T.Show1 (Tagged2 s t) where - showbPrecWith = $(mkShowbPrecWith ''Tagged2) +instance TextShow1 (Tagged2 s t) where + showbPrecWith = $(makeShowbPrecWith ''Tagged2) -instance T.Show2 (Tagged2 s) where - showbPrecWith2 = $(mkShowbPrecWith2 ''Tagged2) +instance TextShow2 (Tagged2 s) where + showbPrecWith2 = $(makeShowbPrecWith2 ''Tagged2)
tests/Derived/Records.hs view
@@ -32,21 +32,20 @@ #endif import Prelude () -import Prelude.Compat hiding (Show) +import Prelude.Compat import Test.QuickCheck (Arbitrary(..), oneof) -import Text.Show as S -import Text.Show.Text.TH (deriveShow, deriveShow1, deriveShow2) +import TextShow.TH (deriveTextShow, deriveTextShow1, deriveTextShow2) -import TransformersCompat as S +import TransformersCompat (Show1(..), Show2(..)) ------------------------------------------------------------------------------- infixl 4 :@: data TyCon a b = TyConPrefix { tc1 :: a, tc2 :: b } | (:@:) { tc3 :: b, tc4 :: a } - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 702 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -67,7 +66,7 @@ infixl 4 :!: data instance TyFamily a b = TyFamilyPrefix { tf1 :: a, tf2 :: b } | (:!:) { tf3 :: b, tf4 :: a } - deriving ( S.Show + deriving ( Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -90,17 +89,17 @@ ------------------------------------------------------------------------------- -instance S.Show a => S.Show1 (TyCon a) where +instance Show a => Show1 (TyCon a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyCon where +instance Show2 TyCon where showsPrecWith2 sp1 sp2 p (TyConPrefix a b) = showsRecord sp1 sp2 "TyConPrefix" "tc1" "tc2" p a b showsPrecWith2 sp1 sp2 p (a :@: b) = showsRecord sp2 sp1 "(:@:)" "tc3" "tc4" p a b -instance S.Show a => S.Show1 (TyFamily a) where +instance Show a => Show1 (TyFamily a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyFamily where +instance Show2 TyFamily where showsPrecWith2 sp1 sp2 p (TyFamilyPrefix a b) = showsRecord sp1 sp2 "TyFamilyPrefix" "tf1" "tf2" p a b showsPrecWith2 sp1 sp2 p (a :!: b) = @@ -120,12 +119,12 @@ ------------------------------------------------------------------------------- -$(deriveShow ''TyCon) -$(deriveShow1 ''TyCon) -$(deriveShow2 ''TyCon) +$(deriveTextShow ''TyCon) +$(deriveTextShow1 ''TyCon) +$(deriveTextShow2 ''TyCon) #if MIN_VERSION_template_haskell(2,7,0) -$(deriveShow 'TyFamilyPrefix) -$(deriveShow1 '(:!:)) -$(deriveShow2 'TyFamilyPrefix) +$(deriveTextShow 'TyFamilyPrefix) +$(deriveTextShow1 '(:!:)) +$(deriveTextShow2 'TyFamilyPrefix) #endif
tests/Derived/TypeSynonyms.hs view
@@ -32,14 +32,13 @@ import qualified Generics.Deriving.TH as Generics (deriveAll) #endif -import Prelude hiding (Show(..)) +import Prelude import Test.QuickCheck (Arbitrary) -import Text.Show as S (Show(..)) -import Text.Show.Text.TH (deriveShow, deriveShow1, deriveShow2) +import TextShow.TH (deriveTextShow, deriveTextShow1, deriveTextShow2) -import TransformersCompat as S (Show1(..), Show2(..), showsUnaryWith) +import TransformersCompat (Show1(..), Show2(..), showsUnaryWith) ------------------------------------------------------------------------------- @@ -51,7 +50,7 @@ instance Functor ((,,,) a b c) where fmap f (a, b, c, d) = (a, b, c, f d) -instance (S.Show a, S.Show b) => S.Show2 ((,,,) a b) where +instance (Show a, Show b) => Show2 ((,,,) a b) where showsPrecWith2 sp1 sp2 _ (a, b, c, d) = showChar '(' . showsPrec 0 a . showChar ',' @@ -68,7 +67,7 @@ , Id (Flip Either (Id b) (Id a)) ) deriving ( Arbitrary - , S.Show + , Show #if __GLASGOW_HASKELL__ >= 702 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -93,7 +92,7 @@ , Id (Flip Either (Id b) (Id a)) ) deriving ( Arbitrary - , S.Show + , Show #if __GLASGOW_HASKELL__ >= 706 , Generic # if defined(__LANGUAGE_DERIVE_GENERIC1__) @@ -104,17 +103,17 @@ ------------------------------------------------------------------------------- -instance S.Show a => S.Show1 (TyCon a) where +instance Show a => Show1 (TyCon a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyCon where +instance Show2 TyCon where showsPrecWith2 sp1 sp2 p (TyCon x) = showsUnaryWith (showsPrecWith2 (showsPrecWith2 showsPrec sp1) (showsPrecWith2 sp1 sp2) ) "TyCon" p x -instance S.Show a => S.Show1 (TyFamily a) where +instance Show a => Show1 (TyFamily a) where showsPrecWith = showsPrecWith2 showsPrec -instance S.Show2 TyFamily where +instance Show2 TyFamily where showsPrecWith2 sp1 sp2 p (TyFamily x) = showsUnaryWith (showsPrecWith2 (showsPrecWith2 showsPrec sp1) (showsPrecWith2 sp1 sp2) @@ -122,14 +121,14 @@ ------------------------------------------------------------------------------- -$(deriveShow ''TyCon) -$(deriveShow1 ''TyCon) -$(deriveShow2 ''TyCon) +$(deriveTextShow ''TyCon) +$(deriveTextShow1 ''TyCon) +$(deriveTextShow2 ''TyCon) #if MIN_VERSION_template_haskell(2,7,0) -$(deriveShow 'TyFamily) -$(deriveShow1 'TyFamily) -$(deriveShow2 'TyFamily) +$(deriveTextShow 'TyFamily) +$(deriveTextShow1 'TyFamily) +$(deriveTextShow2 'TyFamily) #endif #if __GLASGOW_HASKELL__ < 702
tests/Instances/FromStringTextShow.hs view
@@ -15,7 +15,7 @@ module Instances.FromStringTextShow () where import Test.QuickCheck (Arbitrary) -import Text.Show.Text (FromStringShow(..), FromTextShow(..)) +import TextShow (FromStringShow(..), FromTextShow(..)) deriving instance Arbitrary a => Arbitrary (FromStringShow a) deriving instance Arbitrary a => Arbitrary (FromTextShow a)
tests/Instances/GHC/Event.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE CPP #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-orphans #-} {-| @@ -21,8 +22,20 @@ import Test.QuickCheck (Arbitrary(..), oneof) +# if MIN_VERSION_base(4,8,1) +import GHC.Event (Lifetime(..)) +import Test.QuickCheck (arbitraryBoundedEnum) +# endif + instance Arbitrary Event where arbitrary = oneof $ map pure [evtRead, evtWrite] -- TODO: instance Arbitrary FdKey + +# if MIN_VERSION_base(4,8,1) +deriving instance Bounded Lifetime +deriving instance Enum Lifetime +instance Arbitrary Lifetime where + arbitrary = arbitraryBoundedEnum +# endif #endif
tests/Instances/Generic.hs view
@@ -19,7 +19,7 @@ import Test.QuickCheck (Arbitrary(..), oneof) -import Text.Show.Text.Generic (ConType(..)) +import TextShow.Generic (ConType(..)) instance Arbitrary ConType where arbitrary = oneof [pure Rec, pure Tup, pure Pref, Inf <$> arbitrary]
tests/Spec/BuilderSpec.hs view
@@ -15,7 +15,7 @@ import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) -import Text.Show.Text (Builder, fromString, fromText, lengthB, +import TextShow (Builder, fromString, fromText, lengthB, toString, toText, unlinesB, unwordsB) main :: IO ()
tests/Spec/Control/ApplicativeSpec.hs view
@@ -18,8 +18,8 @@ import Instances.Control.Applicative () -import Spec.Utils (prop_matchesShow, prop_matchesShow2, - prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow, prop_matchesTextShow2, + prop_genericTextShow, prop_genericTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -30,8 +30,8 @@ spec :: Spec spec = parallel $ do describe "Const Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> Const Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> Const Int Int -> Bool) describe "ZipList Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> ZipList Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> ZipList Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> ZipList Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ZipList Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> ZipList Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> ZipList Int -> Bool)
tests/Spec/Control/ConcurrentSpec.hs view
@@ -1,3 +1,13 @@+{-| +Module: Spec.Control.ConcurrentSpec +Copyright: (C) 2014-2015 Ryan Scott +License: BSD-style (see the file LICENSE) +Maintainer: Ryan Scott +Stability: Provisional +Portability: GHC + +@hspec@ tests for data types in the "Control.Concurrent" module. +-} module Spec.Control.ConcurrentSpec (main, spec) where import Control.Concurrent (myThreadId) @@ -9,7 +19,7 @@ import Prelude () import Prelude.Compat -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -21,14 +31,14 @@ spec :: Spec spec = parallel $ do describe "BlockReason" $ - prop "Show instance" (prop_matchesShow :: Int -> BlockReason -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> BlockReason -> Bool) describe "ThreadId" $ - prop "Show instance" prop_showThreadId + prop "TextShow instance" prop_showThreadId describe "ThreadStatus" $ - prop "Show instance" (prop_matchesShow :: Int -> ThreadStatus -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ThreadStatus -> Bool) -- | Verifies the 'Show' instance for 'ThreadId' is accurate. prop_showThreadId :: Int -> Property prop_showThreadId p = ioProperty $ do tid <- myThreadId - pure $ prop_matchesShow p tid + pure $ prop_matchesTextShow p tid
tests/Spec/Control/ExceptionSpec.hs view
@@ -16,7 +16,7 @@ import Instances.Control.Exception () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,48 +25,48 @@ main = hspec spec spec :: Spec -spec = parallel . describe "Text.Show.Text.Control.Exception" $ do +spec = parallel . describe "TextShow.Control.Exception" $ do describe "SomeException" $ - prop "Show instance" (prop_matchesShow :: Int -> SomeException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> SomeException -> Bool) describe "IOException" $ - prop "Show instance" (prop_matchesShow :: Int -> IOException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IOException -> Bool) describe "ArithException" $ - prop "Show instance" (prop_matchesShow :: Int -> ArithException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ArithException -> Bool) describe "ArrayException" $ - prop "Show instance" (prop_matchesShow :: Int -> ArrayException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ArrayException -> Bool) describe "AssertionFailed" $ - prop "Show instance" (prop_matchesShow :: Int -> AssertionFailed -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> AssertionFailed -> Bool) #if MIN_VERSION_base(4,7,0) describe "SomeAsyncException" $ - prop "Show instance" (prop_matchesShow :: Int -> SomeAsyncException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> SomeAsyncException -> Bool) #endif describe "AsyncException" $ - prop "Show instance" (prop_matchesShow :: Int -> AsyncException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> AsyncException -> Bool) describe "NonTermination" $ - prop "Show instance" (prop_matchesShow :: Int -> NonTermination -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> NonTermination -> Bool) describe "NestedAtomically" $ - prop "Show instance" (prop_matchesShow :: Int -> NestedAtomically -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> NestedAtomically -> Bool) describe "BlockedIndefinitelyOnMVar" $ - prop "Show instance" (prop_matchesShow :: Int -> BlockedIndefinitelyOnMVar -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> BlockedIndefinitelyOnMVar -> Bool) describe "BlockedIndefinitelyOnSTM" $ - prop "Show instance" (prop_matchesShow :: Int -> BlockedIndefinitelyOnSTM -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> BlockedIndefinitelyOnSTM -> Bool) #if MIN_VERSION_base(4,8,0) describe "AllocationLimitExceeded" $ - prop "Show instance" (prop_matchesShow :: Int -> AllocationLimitExceeded -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> AllocationLimitExceeded -> Bool) #endif describe "Deadlock" $ - prop "Show instance" (prop_matchesShow :: Int -> Deadlock -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Deadlock -> Bool) describe "NoMethodError" $ - prop "Show instance" (prop_matchesShow :: Int -> NoMethodError -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> NoMethodError -> Bool) describe "PatternMatchFail" $ - prop "Show instance" (prop_matchesShow :: Int -> PatternMatchFail -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> PatternMatchFail -> Bool) describe "RecConError" $ - prop "Show instance" (prop_matchesShow :: Int -> RecConError -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> RecConError -> Bool) describe "RecSelError" $ - prop "Show instance" (prop_matchesShow :: Int -> RecSelError -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> RecSelError -> Bool) describe "RecUpdError" $ - prop "Show instance" (prop_matchesShow :: Int -> RecUpdError -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> RecUpdError -> Bool) describe "ErrorCall" $ - prop "Show instance" (prop_matchesShow :: Int -> ErrorCall -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ErrorCall -> Bool) describe "MaskingState" $ - prop "Show instance" (prop_matchesShow :: Int -> MaskingState -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> MaskingState -> Bool)
tests/Spec/Control/Monad/STSpec.hs view
@@ -4,7 +4,7 @@ import Instances.Control.Monad.ST () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -14,4 +14,4 @@ spec :: Spec spec = parallel . describe "ST Int Int" $ - prop "Show instance" (prop_matchesShow :: Int -> ST Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ST Int Int -> Bool)
tests/Spec/Data/ArraySpec.hs view
@@ -22,7 +22,7 @@ import Data.Array (Array) import Data.Array.Unboxed (UArray) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -36,9 +36,9 @@ #if !defined(mingw32_HOST_OS) && MIN_VERSION_text(1,0,0) -- TODO: Figure out why these tests diverge on Windows describe "Array Int Int" $ - prop "Show instance" (prop_matchesShow :: Int -> Array Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Array Int Int -> Bool) describe "UArray Int Int" $ - prop "Show instance" (prop_matchesShow :: Int -> UArray Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> UArray Int Int -> Bool) #else pure () #endif
tests/Spec/Data/BoolSpec.hs view
@@ -12,7 +12,7 @@ -} module Spec.Data.BoolSpec (main, spec) where -import Spec.Utils (prop_matchesShow, prop_genericShow) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -22,5 +22,5 @@ spec :: Spec spec = parallel . describe "Bool" $ do - prop "Show instance" (prop_matchesShow :: Int -> Bool -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Bool -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Bool -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Bool -> Bool)
tests/Spec/Data/ByteStringSpec.hs view
@@ -16,7 +16,7 @@ import Instances.Data.ByteString () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -28,8 +28,8 @@ spec :: Spec spec = parallel $ do describe "strict ByteString" $ - prop "Show instance" (prop_matchesShow :: Int -> BS.ByteString -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> BS.ByteString -> Bool) describe "lazy ByteString" $ - prop "Show instance" (prop_matchesShow :: Int -> BL.ByteString -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> BL.ByteString -> Bool) describe "ShortByteString" $ - prop "Show instance" (prop_matchesShow :: Int -> ShortByteString -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ShortByteString -> Bool)
tests/Spec/Data/CharSpec.hs view
@@ -17,13 +17,13 @@ import Instances.Data.Char () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, it, parallel, shouldBe) import Test.Hspec.QuickCheck (prop) -import Text.Show.Text (fromString) -import Text.Show.Text.Data.Char (asciiTabB) +import TextShow (fromString) +import TextShow.Data.Char (asciiTabB) main :: IO () main = hspec spec @@ -31,8 +31,8 @@ spec :: Spec spec = parallel $ do describe "Char" $ - prop "Show instance" (prop_matchesShow :: Int -> Char -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Char -> Bool) describe "GeneralCategory" $ - prop "Show instance" (prop_matchesShow :: Int -> GeneralCategory -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> GeneralCategory -> Bool) describe "asciiTabB" $ - it "equals asciiTab" $ map fromString asciiTab `shouldBe` elems asciiTabB + it "equals asciiTab" $ map fromString asciiTab `shouldBe` elems asciiTabB
tests/Spec/Data/ComplexSpec.hs view
@@ -12,7 +12,7 @@ import Data.Complex (Complex) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -22,4 +22,4 @@ spec :: Spec spec = parallel . describe "Complex Double" $ - prop "Show instance" (prop_matchesShow :: Int -> Complex Double -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Complex Double -> Bool)
tests/Spec/Data/DataSpec.hs view
@@ -14,7 +14,7 @@ import Instances.Data.Data () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,12 +25,12 @@ spec :: Spec spec = parallel $ do describe "Constr" $ - prop "Show instance" (prop_matchesShow :: Int -> Constr -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Constr -> Bool) describe "ConstrRep" $ - prop "Show instance" (prop_matchesShow :: Int -> ConstrRep -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ConstrRep -> Bool) describe "DataRep" $ - prop "Show instance" (prop_matchesShow :: Int -> DataRep -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> DataRep -> Bool) describe "DataType" $ - prop "Show instance" (prop_matchesShow :: Int -> DataType -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> DataType -> Bool) describe "Fixity" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixity -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixity -> Bool)
tests/Spec/Data/DynamicSpec.hs view
@@ -14,7 +14,7 @@ import Instances.Data.Dynamic () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -24,4 +24,4 @@ spec :: Spec spec = parallel . describe "Dynamic" $ - prop "Show instance" (prop_matchesShow :: Int -> Dynamic -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Dynamic -> Bool)
tests/Spec/Data/EitherSpec.hs view
@@ -12,7 +12,7 @@ import Generics.Deriving.Instances () -import Spec.Utils (prop_matchesShow2, prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow2, prop_genericTextShow, prop_genericTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -22,6 +22,6 @@ spec :: Spec spec = parallel . describe "Either Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> Either Int Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Either Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Either Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> Either Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Either Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Either Int Int -> Bool)
tests/Spec/Data/FixedSpec.hs view
@@ -12,13 +12,13 @@ import Data.Fixed (Fixed, E0, E1, E2, E3, E6, E9, E12, showFixed) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) -import Text.Show.Text (fromString) -import Text.Show.Text.Data.Fixed (showbFixed) +import TextShow (fromString) +import TextShow.Data.Fixed (showbFixed) main :: IO () main = hspec spec @@ -26,21 +26,21 @@ spec :: Spec spec = parallel $ do describe "Fixed E0" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E0 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E0 -> Bool) describe "Fixed E1" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E1 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E1 -> Bool) describe "Fixed E2" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E2 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E2 -> Bool) describe "Fixed E3" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E3 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E3 -> Bool) describe "Fixed E6" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E6 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E6 -> Bool) describe "Fixed E9" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E9 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E9 -> Bool) describe "Fixed E12" $ - prop "Show instance" (prop_matchesShow :: Int -> Fixed E12 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixed E12 -> Bool) describe "showbFixed" $ - prop "has the same output as showFixed" prop_showFixed + prop "has the same output as showFixed" prop_showFixed -- | Verifies 'showFixed' and 'showbFixed' generate the same output. prop_showFixed :: Bool -> Fixed E12 -> Bool
tests/Spec/Data/FloatingSpec.hs view
@@ -22,14 +22,14 @@ import Prelude () import Prelude.Compat -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) import Test.QuickCheck (Gen, arbitrary, suchThat) -import Text.Show.Text (Builder, fromString) -import Text.Show.Text.Data.Floating (showbEFloat, showbFFloat, showbGFloat, +import TextShow (Builder, fromString) +import TextShow.Data.Floating (showbEFloat, showbFFloat, showbGFloat, showbFFloatAlt, showbGFloatAlt) main :: IO () @@ -38,21 +38,21 @@ spec :: Spec spec = parallel $ do describe "Float" $ - prop "Show instance" (prop_matchesShow :: Int -> Float -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Float -> Bool) describe "Double" $ - prop "Show instance" (prop_matchesShow :: Int -> Double -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Double -> Bool) describe "showbEFloat" $ - prop "has the same output as showEFloat" $ prop_showXFloat showEFloat showbEFloat + prop "has the same output as showEFloat" $ prop_showXFloat showEFloat showbEFloat describe "showbFFloat" $ - prop "has the same output as showFFloat" $ prop_showXFloat showFFloat showbFFloat + prop "has the same output as showFFloat" $ prop_showXFloat showFFloat showbFFloat describe "showbGFloat" $ - prop "has the same output as showGFloat" $ prop_showXFloat showGFloat showbGFloat + prop "has the same output as showGFloat" $ prop_showXFloat showGFloat showbGFloat describe "showbFFloatAlt" $ - prop "has the same output as showFFloatAlt" $ prop_showXFloat showFFloatAlt showbFFloatAlt + prop "has the same output as showFFloatAlt" $ prop_showXFloat showFFloatAlt showbFFloatAlt describe "showbGFloatAlt" $ - prop "has the same output as showFFloatAlt" $ prop_showXFloat showGFloatAlt showbGFloatAlt + prop "has the same output as showFFloatAlt" $ prop_showXFloat showGFloatAlt showbGFloatAlt describe "FPFormat" $ - prop "Show instance" (prop_matchesShow :: Int -> FPFormat -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> FPFormat -> Bool) -- | Verifies @showXFloat@ and @showbXFloat@ generate the same output (where @X@ -- is one of E, F, or G).
tests/Spec/Data/Functor/IdentitySpec.hs view
@@ -15,7 +15,7 @@ import Instances.Data.Functor.Identity () -import Spec.Utils (prop_matchesShow1) +import Spec.Utils (prop_matchesTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,4 +25,4 @@ spec :: Spec spec = parallel . describe "Identity Int" $ - prop "Show1 instance" (prop_matchesShow1 :: Int -> Identity Int -> Bool) + prop "TextShow1 instance" (prop_matchesTextShow1 :: Int -> Identity Int -> Bool)
tests/Spec/Data/IntegralSpec.hs view
@@ -18,7 +18,7 @@ import Prelude () import Prelude.Compat -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -29,8 +29,8 @@ import Numeric (showIntAtBase) import Test.QuickCheck (Gen, arbitrary, getNonNegative, suchThat) -import Text.Show.Text (fromString) -import Text.Show.Text.Data.Integral (showbIntAtBase) +import TextShow (fromString) +import TextShow.Data.Integral (showbIntAtBase) #endif main :: IO () @@ -39,27 +39,27 @@ spec :: Spec spec = parallel $ do describe "Int" $ - prop "Show instance" (prop_matchesShow :: Int -> Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Int -> Bool) describe "Int8" $ - prop "Show instance" (prop_matchesShow :: Int -> Int8 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Int8 -> Bool) describe "Int16" $ - prop "Show instance" (prop_matchesShow :: Int -> Int16 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Int16 -> Bool) describe "Int32" $ - prop "Show instance" (prop_matchesShow :: Int -> Int32 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Int32 -> Bool) describe "Int64" $ - prop "Show instance" (prop_matchesShow :: Int -> Int64 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Int64 -> Bool) describe "Integer" $ - prop "Show instance" (prop_matchesShow :: Int -> Integer -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Integer -> Bool) describe "Word" $ - prop "Show instance" (prop_matchesShow :: Int -> Word -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Word -> Bool) describe "Word8" $ - prop "Show instance" (prop_matchesShow :: Int -> Word8 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Word8 -> Bool) describe "Word16" $ - prop "Show instance" (prop_matchesShow :: Int -> Word16 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Word16 -> Bool) describe "Word32" $ - prop "Show instance" (prop_matchesShow :: Int -> Word32 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Word32 -> Bool) describe "Word64" $ - prop "Show instance" (prop_matchesShow :: Int -> Word64 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Word64 -> Bool) #if !defined(mingw32_HOST_OS) && MIN_VERSION_text(1,0,0) -- TODO: Figure out why this diverges on Windows describe "showbIntAtBase" $
tests/Spec/Data/ListSpec.hs view
@@ -10,14 +10,14 @@ -} module Spec.Data.ListSpec (main, spec) where -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) import Text.Show (showListWith) -import Text.Show.Text (fromString, showb) -import Text.Show.Text.Data.List (showbListWith) +import TextShow (fromString, showb) +import TextShow.Data.List (showbListWith) main :: IO () main = hspec spec @@ -25,13 +25,13 @@ spec :: Spec spec = parallel $ do describe "String" $ - prop "Show instance" (prop_matchesShow :: Int -> String -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> String -> Bool) describe "[String]" $ - prop "Show instance" (prop_matchesShow :: Int -> [String] -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> [String] -> Bool) describe "[Int]" $ - prop "Show instance" (prop_matchesShow :: Int -> [Int] -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> [Int] -> Bool) describe "showbListWith" $ - prop "has the same output as showListWith" prop_showListWith + prop "has the same output as showListWith" prop_showListWith -- | Verifies 'showListWith' and 'showbListWith' generate the same output. prop_showListWith :: String -> Bool
tests/Spec/Data/MaybeSpec.hs view
@@ -12,7 +12,7 @@ import Data.Orphans () -import Spec.Utils (prop_matchesShow1, prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow1, prop_genericTextShow, prop_genericTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -22,6 +22,6 @@ spec :: Spec spec = parallel . describe "Maybe Int" $ do - prop "Show1 instance" (prop_matchesShow1 :: Int -> Maybe Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Maybe Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Maybe Int -> Bool) + prop "TextShow1 instance" (prop_matchesTextShow1 :: Int -> Maybe Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Maybe Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Maybe Int -> Bool)
tests/Spec/Data/MonoidSpec.hs view
@@ -18,7 +18,7 @@ import Instances.Data.Monoid () -import Spec.Utils (prop_matchesShow, prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow, prop_genericTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -29,34 +29,34 @@ spec :: Spec spec = parallel $ do describe "All" $ do - prop "Show instance" (prop_matchesShow :: Int -> All -> Bool) - prop "generic Show" (prop_genericShow :: Int -> All -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> All -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> All -> Bool) describe "Any" $ do - prop "Show instance" (prop_matchesShow :: Int -> Any -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Any -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Any -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Any -> Bool) describe "Dual Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Dual Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Dual Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Dual Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Dual Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Dual Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Dual Int -> Bool) describe "First Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> First Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> First Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> First Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> First Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> First Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> First Int -> Bool) describe "Last Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Last Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Last Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Last Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Last Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Last Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Last Int -> Bool) describe "Product Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Product Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Product Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Product Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Product Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Product Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Product Int -> Bool) describe "Sum Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Sum Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Sum Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Sum Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Sum Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Sum Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Sum Int -> Bool) #if MIN_VERSION_base(4,8,0) describe "Alt Maybe Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Alt Maybe Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Alt Maybe Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> Alt Maybe Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Alt Maybe Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Alt Maybe Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> Alt Maybe Int -> Bool) #endif
tests/Spec/Data/OldTypeableSpec.hs view
@@ -26,7 +26,7 @@ #if MIN_VERSION_base(4,7,0) && !(MIN_VERSION_base(4,8,0)) import Data.OldTypeable (TyCon, TypeRep) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -39,9 +39,9 @@ spec = parallel $ do #if MIN_VERSION_base(4,7,0) && !(MIN_VERSION_base(4,8,0)) describe "TypeRep" $ - prop "Show instance" (prop_matchesShow :: Int -> TypeRep -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TypeRep -> Bool) describe "TyCon" $ - prop "Show instance" (prop_matchesShow :: Int -> TyCon -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyCon -> Bool) #else pure () #endif
tests/Spec/Data/OrdSpec.hs view
@@ -20,7 +20,7 @@ import Instances.Data.Ord () -import Spec.Utils (prop_matchesShow, prop_genericShow) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -31,9 +31,9 @@ spec :: Spec spec = parallel $ do describe "Ordering" $ do - prop "Show instance" (prop_matchesShow :: Int -> Ordering -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Ordering -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Ordering -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Ordering -> Bool) #if MIN_VERSION_base(4,6,0) describe "Down Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Down Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Down Int -> Bool) #endif
tests/Spec/Data/ProxySpec.hs view
@@ -14,7 +14,7 @@ import Instances.Data.Proxy () -import Spec.Utils (prop_matchesShow, prop_genericShow) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -24,5 +24,5 @@ spec :: Spec spec = parallel . describe "Proxy Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Proxy Int -> Bool) - prop "generic show" (prop_genericShow :: Int -> Proxy Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Proxy Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Proxy Int -> Bool)
tests/Spec/Data/RatioSpec.hs view
@@ -12,7 +12,7 @@ import Data.Ratio (Ratio) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -22,4 +22,4 @@ spec :: Spec spec = parallel . describe "Ratio Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Ratio Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Ratio Int -> Bool)
tests/Spec/Data/TextSpec.hs view
@@ -14,7 +14,7 @@ import Instances.Data.Text () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -37,20 +37,20 @@ spec :: Spec spec = parallel $ do describe "Builder" $ - prop "Show instance" (prop_matchesShow :: Int -> Builder -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Builder -> Bool) describe "strict Text" $ - prop "Show instance" (prop_matchesShow :: Int -> TS.Text -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TS.Text -> Bool) describe "lazy Text" $ - prop "Show instance" (prop_matchesShow :: Int -> TL.Text -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TL.Text -> Bool) describe "I16" $ - prop "Show instance" (prop_matchesShow :: Int -> I16 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> I16 -> Bool) describe "UnicodeException" $ - prop "Show instance" (prop_matchesShow :: Int -> UnicodeException -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> UnicodeException -> Bool) #if MIN_VERSION_text(1,0,0) describe "Decoding" $ - prop "Show instance" (prop_matchesShow :: Int -> Decoding -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Decoding -> Bool) #endif #if MIN_VERSION_text(1,1,0) describe "Size" $ - prop "Show instance" (prop_matchesShow :: Int -> Size -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Size -> Bool) #endif
tests/Spec/Data/TupleSpec.hs view
@@ -14,8 +14,8 @@ import Instances.Data.Tuple () -import Spec.Utils (prop_matchesShow, prop_matchesShow2, - prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow, prop_matchesTextShow2, + prop_genericTextShow, prop_genericTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -26,73 +26,73 @@ spec :: Spec spec = parallel $ do describe "()" $ do - prop "Show instance" - (prop_matchesShow :: Int -> () -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> () -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> () -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> () -> Bool) describe "(Int, Int)" $ do - prop "Show2 instance" - (prop_matchesShow2 :: Int -> (Int, Int) -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> (Int, Int) -> Bool) - prop "generic Show1" - (prop_genericShow1 :: Int -> (Int, Int) -> Bool) + prop "TextShow2 instance" + (prop_matchesTextShow2 :: Int -> (Int, Int) -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> (Int, Int) -> Bool) + prop "generic TextShow1" + (prop_genericTextShow1 :: Int -> (Int, Int) -> Bool) describe "(Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int) -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> (Int, Int, Int) -> Bool) - prop "generic Show1" - (prop_genericShow1 :: Int -> (Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int) -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> (Int, Int, Int) -> Bool) + prop "generic TextShow1" + (prop_genericTextShow1 :: Int -> (Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int) -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> (Int, Int, Int, Int) -> Bool) - prop "generic Show1" - (prop_genericShow1 :: Int -> (Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int) -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> (Int, Int, Int, Int) -> Bool) + prop "generic TextShow1" + (prop_genericTextShow1 :: Int -> (Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int) -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> (Int, Int, Int, Int, Int) -> Bool) - prop "generic Show1" - (prop_genericShow1 :: Int -> (Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int) -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> (Int, Int, Int, Int, Int) -> Bool) + prop "generic TextShow1" + (prop_genericTextShow1 :: Int -> (Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int) -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> (Int, Int, Int, Int, Int, Int) -> Bool) - prop "generic Show1" - (prop_genericShow1 :: Int -> (Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int) -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> (Int, Int, Int, Int, Int, Int) -> Bool) + prop "generic TextShow1" + (prop_genericTextShow1 :: Int -> (Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int) -> Bool) - prop "generic Show" - (prop_genericShow :: Int -> (Int, Int, Int, Int, Int, Int, Int) -> Bool) - prop "generic Show1" - (prop_genericShow1 :: Int -> (Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "generic TextShow" + (prop_genericTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "generic TextShow1" + (prop_genericTextShow1 :: Int -> (Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) describe "(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)" $ do - prop "Show instance" - (prop_matchesShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool) + prop "TextShow instance" + (prop_matchesTextShow :: Int -> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Bool)
tests/Spec/Data/Type/CoercionSpec.hs view
@@ -23,7 +23,7 @@ import Data.Monoid (All(..)) import Data.Type.Coercion (Coercion) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -36,7 +36,7 @@ spec = parallel $ #if MIN_VERSION_base(4,7,0) describe "Coercion All Bool" $ - prop "Show instance" (prop_matchesShow :: Int -> Coercion All Bool -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Coercion All Bool -> Bool) #else pure () #endif
tests/Spec/Data/Type/EqualitySpec.hs view
@@ -23,7 +23,7 @@ #if MIN_VERSION_base(4,7,0) import Data.Type.Equality ((:~:)) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -36,7 +36,7 @@ spec = parallel $ #if MIN_VERSION_base(4,7,0) describe "Int :~: Int" $ - prop "Show instance" (prop_matchesShow :: Int -> Int :~: Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Int :~: Int -> Bool) #else pure () #endif
tests/Spec/Data/TypeableSpec.hs view
@@ -14,7 +14,7 @@ import Instances.Data.Typeable () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,6 +25,6 @@ spec :: Spec spec = parallel $ do describe "TypeRep" $ - prop "Show instance" (prop_matchesShow :: Int -> TypeRep -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TypeRep -> Bool) describe "TyCon" $ - prop "Show instance" (prop_matchesShow :: Int -> TyCon -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyCon -> Bool)
tests/Spec/Data/VersionSpec.hs view
@@ -4,13 +4,13 @@ import Instances.Data.Version () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) -import Text.Show.Text (fromString) -import Text.Show.Text.Data.Version (showbVersionConcrete) +import TextShow (fromString) +import TextShow.Data.Version (showbVersionConcrete) main :: IO () main = hspec spec @@ -18,9 +18,9 @@ spec :: Spec spec = parallel $ do describe "Version" $ - prop "Show instance" (prop_matchesShow :: Int -> Version -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Version -> Bool) describe "showbVersionConcrete" $ - prop "has the same output as showVersion" prop_showVersion + prop "has the same output as showVersion" prop_showVersion -- | Verifies 'showVersion' and 'showbVersion' generate the same output. prop_showVersion :: Version -> Bool
tests/Spec/Derived/DataFamiliesSpec.hs view
@@ -20,14 +20,14 @@ #if MIN_VERSION_template_haskell(2,7,0) import Derived.DataFamilies (NotAllShow) -import Spec.Utils (prop_matchesShow2, prop_genericShow', prop_genericShow1) +import Spec.Utils (prop_matchesTextShow2, prop_genericTextShow', prop_genericTextShow1) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) # if __GLASGOW_HASKELL__ >= 708 import Derived.DataFamilies (NullaryData) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) # endif #endif @@ -38,13 +38,13 @@ spec = parallel $ do #if MIN_VERSION_template_haskell(2,7,0) describe "NotAllShow Int Int Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> NotAllShow Int Int Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> NotAllShow Int Int Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> NotAllShow Int Int Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> NotAllShow Int Int Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> NotAllShow Int Int Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> NotAllShow Int Int Int Int -> Bool) # if __GLASGOW_HASKELL__ >= 708 describe "NullaryData" $ do - prop "Show instance" (prop_matchesShow :: Int -> NullaryData -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> NullaryData -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> NullaryData -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> NullaryData -> Bool) # endif #else pure ()
tests/Spec/Derived/DatatypeContextsSpec.hs view
@@ -14,7 +14,7 @@ import Derived.DatatypeContexts -import Spec.Utils (prop_matchesShow2) +import Spec.Utils (prop_matchesTextShow2) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,8 +25,8 @@ spec :: Spec spec = parallel $ do describe "TyCon Int Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyCon Int Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyCon Int Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamily Int Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyFamily Int Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamily Int Int Int -> Bool) #endif
tests/Spec/Derived/ExistentialQuantificationSpec.hs view
@@ -14,7 +14,7 @@ import Derived.ExistentialQuantification -import Spec.Utils (prop_matchesShow2) +import Spec.Utils (prop_matchesTextShow2) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,8 +25,8 @@ spec :: Spec spec = parallel $ do describe "TyCon Int Int Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyCon Int Int Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyCon Int Int Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamily Int Int Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyFamily Int Int Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamily Int Int Int Int -> Bool) #endif
tests/Spec/Derived/InfixSpec.hs view
@@ -14,8 +14,8 @@ import Derived.Infix -import Spec.Utils (prop_matchesShow, prop_genericShow, - prop_genericShow', prop_genericShow1) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow, + prop_genericTextShow', prop_genericTextShow1) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -26,20 +26,20 @@ spec :: Spec spec = parallel $ do describe "TyConPlain Int Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> TyConPlain Int Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> TyConPlain Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyConPlain Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyConPlain Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> TyConPlain Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyConPlain Int Int -> Bool) describe "TyConGADT Int Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> TyConGADT Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyConGADT Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyConGADT Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyConGADT Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyConGADT Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyConGADT Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamilyPlain Int Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> TyFamilyPlain Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyFamilyPlain Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyFamilyPlain Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyFamilyPlain Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamilyPlain Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamilyPlain Int Int -> Bool) describe "TyFamilyGADT Int Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> TyFamilyGADT Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyFamilyGADT Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyFamilyGADT Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyFamilyGADT Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamilyGADT Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamilyGADT Int Int -> Bool) #endif
tests/Spec/Derived/MagicHashSpec.hs view
@@ -15,7 +15,7 @@ import Derived.MagicHash -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -26,8 +26,8 @@ spec :: Spec spec = parallel $ do describe "TyCon#" $ - prop "Show instance" (prop_matchesShow :: Int -> TyCon# -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyCon# -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamily#" $ - prop "Show instance" (prop_matchesShow :: Int -> TyFamily# -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyFamily# -> Bool) #endif
tests/Spec/Derived/PolyKindsSpec.hs view
@@ -14,9 +14,9 @@ import Derived.PolyKinds -import Spec.Utils (prop_matchesShow2, prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow2, prop_genericTextShow, prop_genericTextShow1) #if MIN_VERSION_template_haskell(2,7,0) -import Spec.Utils (prop_genericShow') +import Spec.Utils (prop_genericTextShow') #endif import Test.Hspec (Spec, describe, hspec, parallel) @@ -28,20 +28,28 @@ spec :: Spec spec = parallel $ do describe "TyConCompose Either Either Either Maybe Maybe Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyConCompose Either Either Either Maybe Maybe Int Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> TyConCompose Either Either Either Maybe Maybe Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyConCompose Either Either Either Maybe Maybe Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyConCompose Either Either Either Maybe Maybe Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> TyConCompose Either Either Either Maybe Maybe Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyConCompose Either Either Either Maybe Maybe Int Int -> Bool) describe "TyConProxy Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyConProxy Int Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> TyConProxy Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyConProxy Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyConProxy Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> TyConProxy Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyConProxy Int Int -> Bool) + describe "TyConReallyHighKinds (,,,,) Int Int Int Int Int" $ do + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyConReallyHighKinds (,,,,) Int Int Int Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> TyConReallyHighKinds (,,,,) Int Int Int Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyConReallyHighKinds (,,,,) Int Int Int Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamilyCompose Either Either Either Maybe Maybe Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyFamilyCompose Either Either Either Maybe Maybe Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyFamilyCompose Either Either Either Maybe Maybe Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyFamilyCompose Either Either Either Maybe Maybe Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamilyCompose Either Either Either Maybe Maybe Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamilyCompose Either Either Either Maybe Maybe Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamilyCompose Either Either Either Maybe Maybe Int Int -> Bool) describe "TyFamilyProxy Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyFamilyProxy Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyFamilyProxy Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyFamilyProxy Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamilyProxy Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamilyProxy Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamilyProxy Int Int -> Bool) + describe "TyFamilyReallyHighKinds (,,,,) Int Int Int Int Int" $ do + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamilyReallyHighKinds (,,,,) Int Int Int Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamilyReallyHighKinds (,,,,) Int Int Int Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamilyReallyHighKinds (,,,,) Int Int Int Int Int -> Bool) #endif
tests/Spec/Derived/RankNTypesSpec.hs view
@@ -14,7 +14,7 @@ import Derived.Records -import Spec.Utils (prop_matchesShow2) +import Spec.Utils (prop_matchesTextShow2) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -25,8 +25,8 @@ spec :: Spec spec = parallel $ do describe "TyCon Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyCon Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyCon Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamily Int Int" $ - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyFamily Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamily Int Int -> Bool) #endif
tests/Spec/Derived/RecordsSpec.hs view
@@ -14,9 +14,9 @@ import Derived.Records -import Spec.Utils (prop_matchesShow2, prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow2, prop_genericTextShow, prop_genericTextShow1) #if MIN_VERSION_template_haskell(2,7,0) -import Spec.Utils (prop_genericShow') +import Spec.Utils (prop_genericTextShow') #endif import Test.Hspec (Spec, describe, hspec, parallel) @@ -28,12 +28,12 @@ spec :: Spec spec = parallel $ do describe "TyCon Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyCon Int Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> TyCon Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyCon Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyCon Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> TyCon Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyCon Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamily Int Int" $ do - prop "Show2 instance" (prop_matchesShow2 :: Int -> TyFamily Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyFamily Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyFamily Int Int -> Bool) + prop "TextShow2 instance" (prop_matchesTextShow2 :: Int -> TyFamily Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamily Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamily Int Int -> Bool) #endif
tests/Spec/Derived/TypeSynonymsSpec.hs view
@@ -14,9 +14,9 @@ import Derived.TypeSynonyms -import Spec.Utils (prop_matchesShow, prop_genericShow, prop_genericShow1) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow, prop_genericTextShow1) #if MIN_VERSION_template_haskell(2,7,0) -import Spec.Utils (prop_genericShow') +import Spec.Utils (prop_genericTextShow') #endif import Test.Hspec (Spec, describe, hspec, parallel) @@ -28,12 +28,12 @@ spec :: Spec spec = parallel $ do describe "TyCon Int Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> TyCon Int Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> TyCon Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyCon Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyCon Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> TyCon Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyCon Int Int -> Bool) #if MIN_VERSION_template_haskell(2,7,0) describe "TyFamily Int Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> TyFamily Int Int -> Bool) - prop "generic Show" (prop_genericShow' :: Int -> TyFamily Int Int -> Bool) - prop "generic Show1" (prop_genericShow1 :: Int -> TyFamily Int Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TyFamily Int Int -> Bool) + prop "generic TextShow" (prop_genericTextShow' :: Int -> TyFamily Int Int -> Bool) + prop "generic TextShow1" (prop_genericTextShow1 :: Int -> TyFamily Int Int -> Bool) #endif
tests/Spec/Foreign/C/TypesSpec.hs view
@@ -16,7 +16,7 @@ import Instances.Foreign.C.Types () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -27,54 +27,54 @@ spec :: Spec spec = parallel $ do describe "CChar" $ - prop "Show instance" (prop_matchesShow :: Int -> CChar -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CChar -> Bool) describe "CSChar" $ - prop "Show instance" (prop_matchesShow :: Int -> CSChar -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CSChar -> Bool) describe "CUChar" $ - prop "Show instance" (prop_matchesShow :: Int -> CUChar -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUChar -> Bool) describe "CShort" $ - prop "Show instance" (prop_matchesShow :: Int -> CShort -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CShort -> Bool) describe "CUShort" $ - prop "Show instance" (prop_matchesShow :: Int -> CUShort -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUShort -> Bool) describe "CInt" $ - prop "Show instance" (prop_matchesShow :: Int -> CInt -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CInt -> Bool) describe "CUInt" $ - prop "Show instance" (prop_matchesShow :: Int -> CUInt -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUInt -> Bool) describe "CLong" $ - prop "Show instance" (prop_matchesShow :: Int -> CLong -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CLong -> Bool) describe "CULong" $ - prop "Show instance" (prop_matchesShow :: Int -> CULong -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CULong -> Bool) describe "CPtrdiff" $ - prop "Show instance" (prop_matchesShow :: Int -> CPtrdiff -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CPtrdiff -> Bool) describe "CSize" $ - prop "Show instance" (prop_matchesShow :: Int -> CSize -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CSize -> Bool) describe "CWchar" $ - prop "Show instance" (prop_matchesShow :: Int -> CWchar -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CWchar -> Bool) describe "CSigAtomic" $ - prop "Show instance" (prop_matchesShow :: Int -> CSigAtomic -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CSigAtomic -> Bool) describe "CLLong" $ - prop "Show instance" (prop_matchesShow :: Int -> CLLong -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CLLong -> Bool) describe "CULLong" $ - prop "Show instance" (prop_matchesShow :: Int -> CULLong -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CULLong -> Bool) describe "CIntPtr" $ - prop "Show instance" (prop_matchesShow :: Int -> CIntPtr -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CIntPtr -> Bool) describe "CUIntPtr" $ - prop "Show instance" (prop_matchesShow :: Int -> CUIntPtr -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUIntPtr -> Bool) describe "CIntMax" $ - prop "Show instance" (prop_matchesShow :: Int -> CIntMax -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CIntMax -> Bool) describe "CUIntMax" $ - prop "Show instance" (prop_matchesShow :: Int -> CUIntMax -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUIntMax -> Bool) describe "CClock" $ - prop "Show instance" (prop_matchesShow :: Int -> CClock -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CClock -> Bool) describe "CTime" $ - prop "Show instance" (prop_matchesShow :: Int -> CTime -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CTime -> Bool) #if MIN_VERSION_base(4,4,0) describe "CUSeconds" $ - prop "Show instance" (prop_matchesShow :: Int -> CUSeconds -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUSeconds -> Bool) describe "CSUSeconds" $ - prop "Show instance" (prop_matchesShow :: Int -> CSUSeconds -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CSUSeconds -> Bool) #endif describe "CFloat" $ - prop "Show instance" (prop_matchesShow :: Int -> CFloat -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CFloat -> Bool) describe "CDouble" $ - prop "Show instance" (prop_matchesShow :: Int -> CDouble -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CDouble -> Bool)
tests/Spec/Foreign/PtrSpec.hs view
@@ -18,7 +18,7 @@ import Prelude () import Prelude.Compat -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -30,18 +30,18 @@ spec :: Spec spec = parallel $ do describe "Ptr Int" $ - prop "Show instance" (prop_matchesShow :: Int -> Ptr Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Ptr Int -> Bool) describe "FunPtr Int" $ - prop "Show instance" (prop_matchesShow :: Int -> FunPtr Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> FunPtr Int -> Bool) describe "IntPtr" $ - prop "Show instance" (prop_matchesShow :: Int -> IntPtr -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IntPtr -> Bool) describe "WordPtr" $ - prop "Show instance" (prop_matchesShow :: Int -> WordPtr -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> WordPtr -> Bool) describe "ForeignPtr" $ - prop "Show instance" prop_showForeignPtr + prop "TextShow instance" prop_showForeignPtr -- | Verifies the 'Show' instance for 'ForeignPtr' is accurate. prop_showForeignPtr :: Int -> Ptr Int -> Property prop_showForeignPtr p ptr = ioProperty $ do fptr <- newForeignPtr_ ptr - pure $ prop_matchesShow p fptr + pure $ prop_matchesTextShow p fptr
tests/Spec/FromStringTextShowSpec.hs view
@@ -12,12 +12,12 @@ import Instances.FromStringTextShow () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) -import Text.Show.Text (FromStringShow(..), FromTextShow(..)) +import TextShow (FromStringShow(..), FromTextShow(..)) main :: IO () main = hspec spec @@ -25,10 +25,10 @@ spec :: Spec spec = parallel $ do describe "FromStringShow Int" $ - prop "Show instance" (prop_matchesShow :: Int -> FromStringShow Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> FromStringShow Int -> Bool) describe "FromStringShow String" $ - prop "Show instance" (prop_matchesShow :: Int -> FromStringShow String -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> FromStringShow String -> Bool) describe "FromTextShow Int" $ - prop "Show instance" (prop_matchesShow :: Int -> FromTextShow Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> FromTextShow Int -> Bool) describe "FromTextShow String" $ - prop "Show instance" (prop_matchesShow :: Int -> FromTextShow String -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> FromTextShow String -> Bool)
tests/Spec/FunctionsSpec.hs view
@@ -6,21 +6,21 @@ Stability: Provisional Portability: GHC -@hspec@ test for the orphan 'Show' instance for functions. +@hspec@ test for the orphan 'TextShow' instance for functions. -} module Spec.FunctionsSpec (main, spec) where -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) import Text.Show.Functions () -import Text.Show.Text.Functions () +import TextShow.Functions () main :: IO () main = hspec spec spec :: Spec spec = parallel . describe "Int -> Int" $ - prop "Show instance" (prop_matchesShow :: Int -> (Int -> Int) -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> (Int -> Int) -> Bool)
tests/Spec/GHC/Conc/WindowsSpec.hs view
@@ -22,7 +22,7 @@ #if !defined(__GHCJS__) && defined(mingw32_HOST_OS) import GHC.Conc.Windows (ConsoleEvent) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -35,7 +35,7 @@ spec = parallel $ #if !defined(__GHCJS__) && defined(mingw32_HOST_OS) describe "ConsoleEvent" $ - prop "Show instance" (prop_matchesShow :: Int -> ConsoleEvent -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ConsoleEvent -> Bool) #else pure () #endif
tests/Spec/GHC/EventSpec.hs view
@@ -21,8 +21,11 @@ #if !defined(__GHCJS__) && !defined(mingw32_HOST_OS) && MIN_VERSION_base(4,4,0) import GHC.Event (Event) +# if MIN_VERSION_base(4,8,1) +import GHC.Event (Lifetime) +#endif -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -36,9 +39,13 @@ spec = parallel $ do #if !defined(__GHCJS__) && !defined(mingw32_HOST_OS) && MIN_VERSION_base(4,4,0) describe "Event" $ - prop "Show instance" (prop_matchesShow :: Int -> Event -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Event -> Bool) -- describe "FdKey" $ --- prop "Show instance" (prop_matchesShow :: Int -> FdKey -> Bool) +-- prop "TextShow instance" (prop_matchesTextShow :: Int -> FdKey -> Bool) +# if MIN_VERSION_base(4,8,1) + describe "Lifetime" $ + prop "TextShow instance" (prop_matchesTextShow :: Int -> Lifetime -> Bool) +# endif #else pure () #endif
tests/Spec/GHC/FingerprintSpec.hs view
@@ -24,7 +24,7 @@ #if MIN_VERSION_base(4,4,0) import GHC.Fingerprint.Type (Fingerprint) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -37,7 +37,7 @@ spec = parallel $ #if MIN_VERSION_base(4,4,0) describe "Fingerprint" $ - prop "Show instance" (prop_matchesShow :: Int -> Fingerprint -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fingerprint -> Bool) #else pure () #endif
tests/Spec/GHC/GenericsSpec.hs view
@@ -20,7 +20,7 @@ import Instances.GHC.Generics () -import Spec.Utils (prop_matchesShow, prop_genericShow) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -31,35 +31,35 @@ spec :: Spec spec = parallel $ do describe "Fixity" $ do - prop "Show instance" (prop_matchesShow :: Int -> Fixity -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Fixity -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fixity -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Fixity -> Bool) describe "Associativity" $ do - prop "Show instance" (prop_matchesShow :: Int -> Associativity -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Associativity -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Associativity -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Associativity -> Bool) describe "Arity" $ do - prop "Show instance" (prop_matchesShow :: Int -> Arity -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Arity -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Arity -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Arity -> Bool) describe "U1 Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> U1 Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> U1 Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> U1 Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> U1 Int -> Bool) describe "Par1 Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Par1 Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Par1 Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Par1 Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Par1 Int -> Bool) describe "Rec1 Maybe Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> Rec1 Maybe Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> Rec1 Maybe Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Rec1 Maybe Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> Rec1 Maybe Int -> Bool) describe "K1 () Int ()" $ do - prop "Show instance" (prop_matchesShow :: Int -> K1 () Int () -> Bool) - prop "generic Show" (prop_genericShow :: Int -> K1 () Int () -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> K1 () Int () -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> K1 () Int () -> Bool) describe "M1 () () Maybe Int" $ do - prop "Show instance" (prop_matchesShow :: Int -> M1 () () Maybe Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> M1 () () Maybe Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> M1 () () Maybe Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> M1 () () Maybe Int -> Bool) describe "(Maybe :+: Maybe) Int " $ do - prop "Show instance" (prop_matchesShow :: Int -> (Maybe :+: Maybe) Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> (Maybe :+: Maybe) Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> (Maybe :+: Maybe) Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> (Maybe :+: Maybe) Int -> Bool) describe "(Maybe :*: Maybe) Int " $ do - prop "Show instance" (prop_matchesShow :: Int -> (Maybe :*: Maybe) Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> (Maybe :*: Maybe) Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> (Maybe :*: Maybe) Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> (Maybe :*: Maybe) Int -> Bool) describe "(Maybe :.: Maybe) Int " $ do - prop "Show instance" (prop_matchesShow :: Int -> (Maybe :.: Maybe) Int -> Bool) - prop "generic Show" (prop_genericShow :: Int -> (Maybe :.: Maybe) Int -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> (Maybe :.: Maybe) Int -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> (Maybe :.: Maybe) Int -> Bool)
tests/Spec/GHC/RTS/FlagsSpec.hs view
@@ -22,7 +22,7 @@ #if MIN_VERSION_base(4,8,0) import GHC.RTS.Flags -import Spec.Utils (ioProperty, prop_matchesShow) +import Spec.Utils (ioProperty, prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -36,23 +36,23 @@ spec = parallel $ do #if MIN_VERSION_base(4,8,0) describe "RTSFlags" $ - prop "Show instance" prop_showRTSFlags + prop "TextShow instance" prop_showRTSFlags describe "GCFlags" $ - prop "Show instance" prop_showGCFlags + prop "TextShow instance" prop_showGCFlags describe "ConcFlags" $ - prop "Show instance" (prop_matchesShow :: Int -> ConcFlags -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ConcFlags -> Bool) describe "MiscFlags" $ - prop "Show instance" (prop_matchesShow :: Int -> MiscFlags -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> MiscFlags -> Bool) describe "DebugFlags" $ - prop "Show instance" (prop_matchesShow :: Int -> DebugFlags -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> DebugFlags -> Bool) describe "CCFlags" $ - prop "Show instance" prop_showCCFlags + prop "TextShow instance" prop_showCCFlags describe "ProfFlags" $ - prop "Show instance" prop_showProfFlags + prop "TextShow instance" prop_showProfFlags describe "TraceFlags" $ - prop "Show instance" prop_showTraceFlags + prop "TextShow instance" prop_showTraceFlags describe "TickyFlags" $ - prop "Show instance" (prop_matchesShow :: Int -> TickyFlags -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> TickyFlags -> Bool) #else pure () #endif @@ -62,29 +62,29 @@ prop_showRTSFlags :: Int -> Property prop_showRTSFlags p = ioProperty $ do rtsflags <- getRTSFlags - pure $ prop_matchesShow p rtsflags + pure $ prop_matchesTextShow p rtsflags -- | Verifies that the 'Show' instance for 'GCFlags' is accurate. prop_showGCFlags :: Int -> Property prop_showGCFlags p = ioProperty $ do gcflags <- getGCFlags - pure $ prop_matchesShow p gcflags + pure $ prop_matchesTextShow p gcflags -- | Verifies that the 'Show' instance for 'CCFlags' is accurate. prop_showCCFlags :: Int -> Property prop_showCCFlags p = ioProperty $ do ccflags <- getCCFlags - pure $ prop_matchesShow p ccflags + pure $ prop_matchesTextShow p ccflags -- | Verifies that the 'Show' instance for 'ProfFlags' is accurate. prop_showProfFlags :: Int -> Property prop_showProfFlags p = ioProperty $ do profflags <- getProfFlags - pure $ prop_matchesShow p profflags + pure $ prop_matchesTextShow p profflags -- | Verifies that the 'Show' instance for 'TraceFlags' is accurate. prop_showTraceFlags :: Int -> Property prop_showTraceFlags p = ioProperty $ do traceflags <- getTraceFlags - pure $ prop_matchesShow p traceflags + pure $ prop_matchesTextShow p traceflags #endif
tests/Spec/GHC/StaticPtrSpec.hs view
@@ -22,7 +22,7 @@ #if MIN_VERSION_base(4,8,0) import GHC.StaticPtr (StaticPtrInfo) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -35,7 +35,7 @@ spec = parallel $ #if MIN_VERSION_base(4,8,0) describe "StaticPtrInfo" $ - prop "Show instance" (prop_matchesShow :: Int -> StaticPtrInfo -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> StaticPtrInfo -> Bool) #else pure () #endif
tests/Spec/GHC/StatsSpec.hs view
@@ -22,7 +22,7 @@ #if MIN_VERSION_base(4,5,0) import GHC.Stats (GCStats) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -35,7 +35,7 @@ spec = parallel $ #if MIN_VERSION_base(4,5,0) describe "GCStats" $ - prop "Show instance" (prop_matchesShow :: Int -> GCStats -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> GCStats -> Bool) #else pure () #endif
tests/Spec/GHC/TypeLitsSpec.hs view
@@ -26,7 +26,7 @@ #if MIN_VERSION_base(4,6,0) import GHC.TypeLits -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (describe) import Test.Hspec.QuickCheck (prop) @@ -39,24 +39,24 @@ spec = parallel $ do #if MIN_VERSION_base(4,7,0) describe "SomeNat" $ - prop "Show instance" (prop_matchesShow :: Int -> SomeNat -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> SomeNat -> Bool) describe "SomeSymbol" $ - prop "Show instance" (prop_matchesShow :: Int -> SomeSymbol -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> SomeSymbol -> Bool) #elif MIN_VERSION_base(4,6,0) describe "IsEven 0" $ - prop "Show instance" (prop_matchesShow :: Int -> IsEven 0 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IsEven 0 -> Bool) describe "IsEven 1" $ - prop "Show instance" (prop_matchesShow :: Int -> IsEven 1 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IsEven 1 -> Bool) describe "IsEven 2" $ - prop "Show instance" (prop_matchesShow :: Int -> IsEven 2 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IsEven 2 -> Bool) describe "IsZero 0" $ - prop "Show instance" (prop_matchesShow :: Int -> IsZero 0 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IsZero 0 -> Bool) describe "IsZero 1" $ - prop "Show instance" (prop_matchesShow :: Int -> IsZero 1 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IsZero 1 -> Bool) describe "Sing 0" $ - prop "Show instance" (prop_matchesShow :: Int -> Sing 0 -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Sing 0 -> Bool) describe "Sing \"a\"" $ - prop "Show instance" (prop_matchesShow :: Int -> Sing "a" -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Sing "a" -> Bool) #else pure () #endif
tests/Spec/GenericSpec.hs view
@@ -12,17 +12,17 @@ import Instances.Generic () -import Spec.Utils (prop_matchesShow, prop_genericShow) +import Spec.Utils (prop_matchesTextShow, prop_genericTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) -import Text.Show.Text.Generic (ConType) +import TextShow.Generic (ConType) main :: IO () main = hspec spec spec :: Spec spec = parallel . describe "ConType" $ do - prop "Show instance" (prop_matchesShow :: Int -> ConType -> Bool) - prop "generic Show" (prop_genericShow :: Int -> ConType -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ConType -> Bool) + prop "generic TextShow" (prop_genericTextShow :: Int -> ConType -> Bool)
tests/Spec/Numeric/NaturalSpec.hs view
@@ -14,7 +14,7 @@ import Numeric.Natural (Natural) -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -24,4 +24,4 @@ spec :: Spec spec = parallel . describe "Natural" $ - prop "Show instance" (prop_matchesShow :: Int -> Natural -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Natural -> Bool)
tests/Spec/System/ExitSpec.hs view
@@ -12,7 +12,7 @@ import Instances.System.Exit () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import System.Exit (ExitCode) @@ -24,4 +24,4 @@ spec :: Spec spec = parallel . describe "ExitCode" $ - prop "Show instance" (prop_matchesShow :: Int -> ExitCode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> ExitCode -> Bool)
tests/Spec/System/IOSpec.hs view
@@ -22,7 +22,7 @@ import Prelude () import Prelude.Compat -import Spec.Utils (ioProperty, prop_matchesShow) +import Spec.Utils (ioProperty, prop_matchesTextShow) import System.IO (BufferMode, IOMode, HandlePosn, Newline, NewlineMode, SeekMode, Handle, mkTextEncoding) @@ -37,29 +37,29 @@ spec :: Spec spec = parallel $ do describe "Handle" $ - prop "Show instance" (prop_matchesShow :: Int -> Handle -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Handle -> Bool) describe "IOMode" $ - prop "Show instance" (prop_matchesShow :: Int -> IOMode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> IOMode -> Bool) describe "BufferMode" $ - prop "Show instance" (prop_matchesShow :: Int -> BufferMode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> BufferMode -> Bool) describe "HandlePosn" $ - prop "Show instance" (prop_matchesShow :: Int -> HandlePosn -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> HandlePosn -> Bool) describe "SeekMode" $ - prop "Show instance" (prop_matchesShow :: Int -> SeekMode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> SeekMode -> Bool) describe "TextEncoding" $ - prop "Show instance" prop_showTextEncoding + prop "TextShow instance" prop_showTextEncoding #if MIN_VERSION_base(4,4,0) describe "CodingProgress" $ - prop "Show instance" (prop_matchesShow :: Int -> CodingProgress -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CodingProgress -> Bool) describe "CodingFailureMode" $ - prop "Show instance" (prop_matchesShow :: Int -> CodingFailureMode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CodingFailureMode -> Bool) #endif describe "Newline" $ - prop "Show instance" (prop_matchesShow :: Int -> Newline -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Newline -> Bool) describe "NewlineMode" $ - prop "Show instance" (prop_matchesShow :: Int -> NewlineMode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> NewlineMode -> Bool) --- | Verifies the 'Show' instance for 'TextEncoding' is accurate. +-- | Verifies the 'TextShow' instance for 'TextEncoding' is accurate. prop_showTextEncoding :: Int -> Property prop_showTextEncoding p = ioProperty $ do -- Based on this description: @@ -69,4 +69,4 @@ , "UTF-32", "UTF-32BE", "UTF-32LE" ] tenc <- mkTextEncoding utf - pure $ prop_matchesShow p tenc + pure $ prop_matchesTextShow p tenc
tests/Spec/System/Posix/TypesSpec.hs view
@@ -14,7 +14,7 @@ import Instances.System.Posix.Types () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import System.Posix.Types @@ -29,56 +29,56 @@ spec :: Spec spec = parallel $ do describe "Fd" $ - prop "Show instance" (prop_matchesShow :: Int -> Fd -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Fd -> Bool) #if defined(HTYPE_DEV_T) describe "CDev" $ - prop "Show instance" (prop_matchesShow :: Int -> CDev -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CDev -> Bool) #endif #if defined(HTYPE_INO_T) describe "CIno" $ - prop "Show instance" (prop_matchesShow :: Int -> CIno -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CIno -> Bool) #endif #if defined(HTYPE_MODE_T) describe "CMode" $ - prop "Show instance" (prop_matchesShow :: Int -> CMode -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CMode -> Bool) #endif #if defined(HTYPE_OFF_T) describe "COff" $ - prop "Show instance" (prop_matchesShow :: Int -> COff -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> COff -> Bool) #endif #if defined(HTYPE_PID_T) describe "CPid" $ - prop "Show instance" (prop_matchesShow :: Int -> CPid -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CPid -> Bool) #endif #if defined(HTYPE_SSIZE_T) describe "CSsize" $ - prop "Show instance" (prop_matchesShow :: Int -> CSsize -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CSsize -> Bool) #endif #if defined(HTYPE_GID_T) describe "CGid" $ - prop "Show instance" (prop_matchesShow :: Int -> CGid -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CGid -> Bool) #endif #if defined(HTYPE_NLINK_T) describe "CNlink" $ - prop "Show instance" (prop_matchesShow :: Int -> CNlink -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CNlink -> Bool) #endif #if defined(HTYPE_UID_T) describe "CUid" $ - prop "Show instance" (prop_matchesShow :: Int -> CUid -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CUid -> Bool) #endif #if defined(HTYPE_CC_T) describe "CCc" $ - prop "Show instance" (prop_matchesShow :: Int -> CCc -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CCc -> Bool) #endif #if defined(HTYPE_SPEED_T) describe "CSpeed" $ - prop "Show instance" (prop_matchesShow :: Int -> CSpeed -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CSpeed -> Bool) #endif #if defined(HTYPE_TCFLAG_T) describe "CTcflag" $ - prop "Show instance" (prop_matchesShow :: Int -> CTcflag -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CTcflag -> Bool) #endif #if defined(HTYPE_RLIM_T) describe "CRLim" $ - prop "Show instance" (prop_matchesShow :: Int -> CRLim -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> CRLim -> Bool) #endif
tests/Spec/Text/ReadSpec.hs view
@@ -14,7 +14,7 @@ import Instances.Text.Read () -import Spec.Utils (prop_matchesShow) +import Spec.Utils (prop_matchesTextShow) import Test.Hspec (Spec, describe, hspec, parallel) import Test.Hspec.QuickCheck (prop) @@ -30,8 +30,8 @@ spec :: Spec spec = parallel $ do describe "Lexeme" $ - prop "Show instance" (prop_matchesShow :: Int -> Lexeme -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Lexeme -> Bool) #if MIN_VERSION_base(4,7,0) describe "Number" $ - prop "Show instance" (prop_matchesShow :: Int -> Number -> Bool) + prop "TextShow instance" (prop_matchesTextShow :: Int -> Number -> Bool) #endif
tests/Spec/Utils.hs view
@@ -12,12 +12,12 @@ -} module Spec.Utils ( ioProperty - , prop_matchesShow - , prop_matchesShow1 - , prop_matchesShow2 - , prop_genericShow - , prop_genericShow' - , prop_genericShow1 + , prop_matchesTextShow + , prop_matchesTextShow1 + , prop_matchesTextShow2 + , prop_genericTextShow + , prop_genericTextShow' + , prop_genericTextShow1 ) where #include "generic.h" @@ -27,11 +27,9 @@ # if defined(__LANGUAGE_DERIVE_GENERIC1__) import GHC.Generics (Generic1, Rep1) # endif -import Text.Show.Text.Generic +import TextShow.Generic #endif -import Prelude hiding (Show) - #if MIN_VERSION_QuickCheck(2,7,0) import qualified Test.QuickCheck as QC (ioProperty) #else @@ -39,10 +37,11 @@ #endif import Test.QuickCheck (Property, Testable) -import qualified Text.Show as S (Show) -import Text.Show.Text as T +import TextShow (TextShow(..), TextShow1(..), TextShow2(..), + Builder, FromStringShow(..)) -import TransformersCompat as S +import TransformersCompat (Show1, Show2, + FromStringShow1(..), FromStringShow2(..)) ioProperty :: Testable prop => IO prop -> Property #if MIN_VERSION_QuickCheck(2,7,0) @@ -53,20 +52,20 @@ -- | Verifies that a type's @Show@ instances coincide for both 'String's and 'Text', -- irrespective of precedence. -prop_matchesShow :: (S.Show a, T.Show a) => Int -> a -> Bool -prop_matchesShow p x = showbPrec p (FromStringShow x) == showbPrec p x +prop_matchesTextShow :: (Show a, TextShow a) => Int -> a -> Bool +prop_matchesTextShow p x = showbPrec p (FromStringShow x) == showbPrec p x -- | Verifies that a type's @Show1@ instances coincide for both 'String's and 'Text', -- irrespective of precedence. -prop_matchesShow1 :: (S.Show1 f, T.Show1 f) => Int -> f a -> Bool -prop_matchesShow1 p x = showbPrecWith showb27Prec p (FromStringShow1 x) +prop_matchesTextShow1 :: (Show1 f, TextShow1 f) => Int -> f a -> Bool +prop_matchesTextShow1 p x = showbPrecWith showb27Prec p (FromStringShow1 x) == showbPrecWith showb27Prec p x -- | Verifies that a type's @Show2@ instances coincide for both 'String's and 'Text', -- irrespective of precedence. -prop_matchesShow2 :: (S.Show2 f, T.Show2 f) => Int -> f a b -> Bool -prop_matchesShow2 p x = showbPrecWith2 showb27Prec showb42Prec p (FromStringShow2 x) - == showbPrecWith2 showb27Prec showb42Prec p x +prop_matchesTextShow2 :: (Show2 f, TextShow2 f) => Int -> f a b -> Bool +prop_matchesTextShow2 p x = showbPrecWith2 showb27Prec showb42Prec p (FromStringShow2 x) + == showbPrecWith2 showb27Prec showb42Prec p x -- | Show the number 27, which certain parody singer-songwriters find humorous. -- Useful for testing higher-order @Show@ classes. @@ -78,37 +77,37 @@ showb42Prec :: Int -> a -> Builder showb42Prec p _ = showbPrec p $ Just (42 :: Int) --- | Verifies that a type's @Show@ instance coincides with the output produced +-- | Verifies that a type's 'TextShow' instance coincides with the output produced -- by the equivalent 'Generic' functions. #if __GLASGOW_HASKELL__ >= 702 -prop_genericShow :: (T.Show a, Generic a, GShow (Rep a)) - => Int -> a -> Bool -prop_genericShow p x = showbPrec p x == genericShowbPrec p x +prop_genericTextShow :: (TextShow a, Generic a, GTextShow (Rep a)) + => Int -> a -> Bool +prop_genericTextShow p x = showbPrec p x == genericShowbPrec p x #else -prop_genericShow :: Int -> a -> Bool -prop_genericShow _ _ = True +prop_genericTextShow :: Int -> a -> Bool +prop_genericTextShow _ _ = True #endif --- | Behaves exactly like 'prop_genericShow', except only for GHC 7.6 and above. +-- | Behaves exactly like 'prop_genericTextShow', except only for GHC 7.6 and above. -- This is useful with type families, which couldn't properly have derived 'Generic' -- instances until GHC 7.6 due to a bug. #if __GLASGOW_HASKELL__ >= 706 -prop_genericShow' :: (T.Show a, Generic a, GShow (Rep a)) - => Int -> a -> Bool -prop_genericShow' = prop_genericShow +prop_genericTextShow' :: (TextShow a, Generic a, GTextShow (Rep a)) + => Int -> a -> Bool +prop_genericTextShow' = prop_genericTextShow #else -prop_genericShow' :: Int -> f a -> Bool -prop_genericShow' _ _ = True +prop_genericTextShow' :: Int -> f a -> Bool +prop_genericTextShow' _ _ = True #endif --- | Verifies that a type's @Show1@ instance coincides with the output produced +-- | Verifies that a type's 'TextShow1' instance coincides with the output produced -- by the equivalent 'Generic1' functions. #if defined(__LANGUAGE_DERIVE_GENERIC1__) -prop_genericShow1 :: (T.Show1 f, Generic1 f, GShow1 (Rep1 f)) - => Int -> f a -> Bool -prop_genericShow1 p x = showbPrecWith showb27Prec p x +prop_genericTextShow1 :: (TextShow1 f, Generic1 f, GTextShow1 (Rep1 f)) + => Int -> f a -> Bool +prop_genericTextShow1 p x = showbPrecWith showb27Prec p x == genericShowbPrecWith showb27Prec p x #else -prop_genericShow1 :: Int -> f a -> Bool -prop_genericShow1 _ _ = True +prop_genericTextShow1 :: Int -> f a -> Bool +prop_genericTextShow1 _ _ = True #endif
tests/TransformersCompat.hs view
@@ -35,7 +35,7 @@ -- * Helper functions showsUnaryWith, showsBinaryWith, - -- * Conversion between @String@ and @Text@ 'Show1'/'Show2' + -- * Conversion between @Text-@ and @String@ @Show1@/@Show2@ FromStringShow1(..), FromStringShow2(..) ) where @@ -43,29 +43,29 @@ #include "generic.h" #include "inline.h" -import Control.Applicative (Const(..)) +import Control.Applicative (Const(..)) -- #if __GLASGOW_HASKELL__ >= 708 --- import Data.Data (Data, Typeable) +-- import Data.Data (Data, Typeable) -- #endif -import Data.Functor.Identity (Identity(..)) -import Data.Text.Lazy.Builder (Builder) +import Data.Functor.Identity (Identity(..)) +import Data.Text.Lazy.Builder (Builder) #if __GLASGOW_HASKELL__ >= 702 -import GHC.Generics (Generic) +import GHC.Generics (Generic) # if defined(__LANGUAGE_DERIVE_GENERIC1__) -import GHC.Generics (Generic1) +import GHC.Generics (Generic1) # endif #endif -import Prelude () -import Prelude.Compat +import Prelude () +import Prelude.Compat import Text.Read (Read(..), readListPrecDefault) -import qualified Text.Show.Text as T (Show, Show1, Show2) -import Text.Show.Text (fromString, showbPrec, showbPrecWith, - showbPrecWith2, toString) +import TextShow (TextShow(showbPrec), TextShow1(..), TextShow2(..), + fromString, toString) + -- | Lifting of the 'Show' class to unary type constructors. class Show1 f where -- | Lift a 'showsPrec' function through the type constructor. @@ -111,11 +111,11 @@ readListPrec = readListPrecDefault INLINE_INST_FUN(readListPrec) -instance (Show1 f, Show a) => T.Show (FromStringShow1 f a) where +instance (Show1 f, Show a) => TextShow (FromStringShow1 f a) where showbPrec = showbPrecWith (showsToShowb showsPrec) INLINE_INST_FUN(showbPrec) -instance Show1 f => T.Show1 (FromStringShow1 f) where +instance Show1 f => TextShow1 (FromStringShow1 f) where showbPrecWith sp p (FromStringShow1 x) = fromString $ showsPrecWith (showbToShows sp) p x "" INLINE_INST_FUN(showbPrecWith) @@ -162,15 +162,15 @@ readListPrec = readListPrecDefault INLINE_INST_FUN(readListPrec) -instance (Show2 f, Show a, Show b) => T.Show (FromStringShow2 f a b) where +instance (Show2 f, Show a, Show b) => TextShow (FromStringShow2 f a b) where showbPrec = showbPrecWith (showsToShowb showsPrec) INLINE_INST_FUN(showbPrec) -instance (Show2 f, Show a) => T.Show1 (FromStringShow2 f a) where +instance (Show2 f, Show a) => TextShow1 (FromStringShow2 f a) where showbPrecWith = showbPrecWith2 (showsToShowb showsPrec) INLINE_INST_FUN(showbPrecWith) -instance Show2 f => T.Show2 (FromStringShow2 f) where +instance Show2 f => TextShow2 (FromStringShow2 f) where showbPrecWith2 sp1 sp2 p (FromStringShow2 x) = fromString $ showsPrecWith2 (showbToShows sp1) (showbToShows sp2) p x "" INLINE_INST_FUN(showbPrecWith2) @@ -235,3 +235,11 @@ instance Show2 Const where showsPrecWith2 sp _ d (Const x) = showsUnaryWith sp "Const" d x + +instance (Show a, Show b, Show c) => Show2 ((,,,,) a b c) where + showsPrecWith2 sp1 sp2 _ (a, b, c, d, e) = + showChar '(' . shows a . showChar ',' + . shows b . showChar ',' + . shows c . showChar ',' + . sp1 0 d . showChar ',' + . sp2 0 e . showChar ')'
text-show.cabal view
@@ -1,47 +1,40 @@ name: text-show -version: 1 +version: 2 synopsis: Efficient conversion of values into Text description: @text-show@ offers a replacement for the @Show@ typeclass intended for use with @Text@ instead of @String@s. This package was created in the spirit of @<http://hackage.haskell.org/package/bytestring-show bytestring-show>@. . - At the moment, @text-show@ provides @Show@ instances for most data + At the moment, @text-show@ provides instances for most data types in the @<http://hackage.haskell.org/package/array array>@, @<http://hackage.haskell.org/package/base base>@, @<http://hackage.haskell.org/package/bytestring bytestring>@, and @<http://hackage.haskell.org/package/text text>@ packages. Therefore, much of the source code for @text-show@ consists of borrowed code from those packages in order to ensure that the - behaviors of the two @Show@ typeclasses coincide. + behaviors of @Show@ and @TextShow@ coincide. . - For most uses, simply importing "Text.Show.Text" + For most uses, simply importing "TextShow" will suffice: . @ module Main where . - import Data.Text (Text) - import Prelude hiding (Show(..), print) - import Text.Show.Text - . - hello :: Text - hello = show (Just \"Hello, World!\") + import TextShow . main :: IO () - main = print hello + main = printT (Just \"Hello, World!\") @ . If you desire it, there are also monomorphic versions of the @showb@ - function available in the submodules of "Text.Show.Text". A naming - convention is present in which functions that show different values - depending on the precedence end with @Prec@ (e.g., @showbIntPrec@), - whereas functions that show the same values regardless of - precedence do not end with @Prec@ (e.g., @showbBool@). + function available in the submodules of "TextShow". See the + <https://github.com/RyanGlScott/text-show/wiki/Naming-conventions naming conventions> + page for more information. . - Support for automatically deriving @Show@ instances can be found - in the "Text.Show.Text.TH" and "Text.Show.Text.Generic" modules. - If you don't know which one to use, use @Text.Show.Text.TH@. + Support for automatically deriving @TextShow@ instances can be found + in the "TextShow.TH" and "TextShow.Generic" modules. If you don't + know which one to use, use "TextShow.TH". homepage: https://github.com/RyanGlScott/text-show bug-reports: https://github.com/RyanGlScott/text-show/issues license: BSD3 @@ -61,77 +54,77 @@ location: https://github.com/RyanGlScott/text-show library - exposed-modules: Text.Show.Text - Text.Show.Text.Control.Applicative - Text.Show.Text.Control.Concurrent - Text.Show.Text.Control.Exception - Text.Show.Text.Control.Monad.ST - Text.Show.Text.Data.Array - Text.Show.Text.Data.Bool - Text.Show.Text.Data.ByteString - Text.Show.Text.Data.Char - Text.Show.Text.Data.Complex - Text.Show.Text.Data.Data - Text.Show.Text.Data.Dynamic - Text.Show.Text.Data.Either - Text.Show.Text.Data.Fixed - Text.Show.Text.Data.Floating - Text.Show.Text.Data.Functor.Identity - Text.Show.Text.Debug.Trace - Text.Show.Text.Debug.Trace.Generic - Text.Show.Text.Debug.Trace.TH - Text.Show.Text.Generic - Text.Show.Text.Data.Integral - Text.Show.Text.Data.List - Text.Show.Text.Data.Maybe - Text.Show.Text.Data.Monoid - Text.Show.Text.Data.Ord - Text.Show.Text.Data.Proxy - Text.Show.Text.Data.Ratio - Text.Show.Text.Data.Text - Text.Show.Text.Data.Tuple - Text.Show.Text.Data.Typeable - Text.Show.Text.Data.Version - Text.Show.Text.Data.Void - Text.Show.Text.Foreign.C.Types - Text.Show.Text.Foreign.Ptr - Text.Show.Text.Functions - Text.Show.Text.GHC.Generics - Text.Show.Text.Numeric.Natural - Text.Show.Text.System.Exit - Text.Show.Text.System.IO - Text.Show.Text.System.Posix.Types - Text.Show.Text.Text.Read - Text.Show.Text.TH + exposed-modules: TextShow + TextShow.Control.Applicative + TextShow.Control.Concurrent + TextShow.Control.Exception + TextShow.Control.Monad.ST + TextShow.Data.Array + TextShow.Data.Bool + TextShow.Data.ByteString + TextShow.Data.Char + TextShow.Data.Complex + TextShow.Data.Data + TextShow.Data.Dynamic + TextShow.Data.Either + TextShow.Data.Fixed + TextShow.Data.Floating + TextShow.Data.Functor.Identity + TextShow.Debug.Trace + TextShow.Debug.Trace.Generic + TextShow.Debug.Trace.TH + TextShow.Generic + TextShow.Data.Integral + TextShow.Data.List + TextShow.Data.Maybe + TextShow.Data.Monoid + TextShow.Data.Ord + TextShow.Data.Proxy + TextShow.Data.Ratio + TextShow.Data.Text + TextShow.Data.Tuple + TextShow.Data.Typeable + TextShow.Data.Version + TextShow.Data.Void + TextShow.Foreign.C.Types + TextShow.Foreign.Ptr + TextShow.Functions + TextShow.GHC.Generics + TextShow.Numeric.Natural + TextShow.System.Exit + TextShow.System.IO + TextShow.System.Posix.Types + TextShow.Text.Read + TextShow.TH -- Only exports functions if using Windows - Text.Show.Text.GHC.Conc.Windows + TextShow.GHC.Conc.Windows -- Only exports functions if base >= 4.4 - Text.Show.Text.GHC.Fingerprint + TextShow.GHC.Fingerprint -- Only exports functions if base >= 4.4 and not using Windows - Text.Show.Text.GHC.Event + TextShow.GHC.Event -- Only exports functions if base >= 4.5 - Text.Show.Text.GHC.Stats + TextShow.GHC.Stats -- Only exports functions if base >= 4.6 - Text.Show.Text.GHC.TypeLits + TextShow.GHC.TypeLits -- Only exports functions if base >= 4.7 - Text.Show.Text.Data.Type.Coercion - Text.Show.Text.Data.Type.Equality + TextShow.Data.Type.Coercion + TextShow.Data.Type.Equality -- Only exports functions if base >= 4.7 && < 4.8 - Text.Show.Text.Data.OldTypeable + TextShow.Data.OldTypeable -- Only exports functions if base >= 4.8 - Text.Show.Text.GHC.RTS.Flags - Text.Show.Text.GHC.StaticPtr - other-modules: Text.Show.Text.Classes - Text.Show.Text.Data.Typeable.Utils - Text.Show.Text.Instances - Text.Show.Text.TH.Internal - Text.Show.Text.Utils + TextShow.GHC.RTS.Flags + TextShow.GHC.StaticPtr + other-modules: TextShow.Classes + TextShow.Data.Typeable.Utils + TextShow.Instances + TextShow.TH.Internal + TextShow.Utils build-depends: array >= 0.3 && < 0.6 , base >= 4.3 && < 5 , base-compat >= 0.8.1 && < 1 @@ -313,7 +306,7 @@ , quickcheck-instances >= 0.1 && < 0.4 , tagged >= 0.8.1 && < 1 , text >= 0.11.1 && < 1.3 - , text-show == 1 + , text-show == 2 , transformers >= 0.2.1 && < 0.5 , transformers-compat >= 0.3 && < 1 , void >= 0.5 && < 1