Copyright | (c) The University of Glasgow 2001 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | libraries@haskell.org |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Converting values to readable strings:
the Show
class and associated functions.
Documentation
Conversion of values to readable String
s.
Derived instances of Show
have the following properties, which
are compatible with derived instances of Read
:
- The result of
show
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrec
will produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
show
will produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show
is equivalent to
instance (Show a) => Show (Tree a) where showsPrec d (Leaf m) = showParen (d > app_prec) $ showString "Leaf " . showsPrec (app_prec+1) m where app_prec = 10 showsPrec d (u :^: v) = showParen (d > up_prec) $ showsPrec (up_prec+1) u . showString " :^: " . showsPrec (up_prec+1) v where up_prec = 5
Note that right-associativity of :^:
is ignored. For example,
produces the stringshow
(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"
.
:: Int | the operator precedence of the enclosing
context (a number from |
-> a | the value to be converted to a |
-> ShowS |
Convert a value to a readable String
.
showsPrec
should satisfy the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
Derived instances of Read
and Show
satisfy the following:
That is, readsPrec
parses the string produced by
showsPrec
, and delivers the value that showsPrec
started with.
Instances
Show ByteArray Source # | Since: base-4.17.0.0 |
Show Timeout Source # | Since: base-4.0 |
Show Void | @since base-4.8.0.0 |
Show ByteOrder | @since base-4.11.0.0 |
Show ClosureType | |
Defined in GHC.Internal.ClosureTypes | |
Show BlockReason | @since base-4.3.0.0 |
Defined in GHC.Internal.Conc.Sync | |
Show ThreadId | @since base-4.2.0.0 |
Show ThreadStatus | @since base-4.3.0.0 |
Defined in GHC.Internal.Conc.Sync | |
Show NestedAtomically | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show NoMatchingContinuationPrompt | @since base-4.18 |
Defined in GHC.Internal.Control.Exception.Base | |
Show NoMethodError | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show NonTermination | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show PatternMatchFail | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show RecConError | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show RecSelError | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show RecUpdError | @since base-4.0 |
Defined in GHC.Internal.Control.Exception.Base | |
Show TypeError | @since base-4.9.0.0 |
Show Constr | @since base-4.0.0.0 |
Show ConstrRep | @since base-4.0.0.0 |
Show DataRep | @since base-4.0.0.0 |
Show DataType | @since base-4.0.0.0 |
Show Fixity | @since base-4.0.0.0 |
Show Dynamic | @since base-2.01 |
Show All | @since base-2.01 |
Show Any | @since base-2.01 |
Show SomeTypeRep | @since base-4.10.0.0 |
Defined in GHC.Internal.Data.Typeable.Internal | |
Show Version | @since base-2.01 |
Show ControlMessage | @since base-4.4.0.0 |
Show Event | @since base-4.4.0.0 |
Show EventLifetime | @since base-4.8.0.0 |
Show Lifetime | @since base-4.8.1.0 |
Show Timeout | @since base-4.4.0.0 |
Show FdKey | @since base-4.4.0.0 |
Show State | @since base-4.4.0.0 |
Show State | @since base-4.7.0.0 |
Show Unique | @since base-4.3.1.0 |
Show ErrorCall | @since base-4.0.0.0 |
Show ArithException | @since base-4.0.0.0 |
Defined in GHC.Internal.Exception.Type | |
Show SomeException | Since: ghc-internal-3.0 |
Defined in GHC.Internal.Exception.Type | |
Show Fingerprint | @since base-4.7.0.0 |
Defined in GHC.Internal.Fingerprint.Type | |
Show CBool | |
Show CChar | |
Show CClock | |
Show CDouble | |
Show CFloat | |
Show CInt | |
Show CIntMax | |
Show CIntPtr | |
Show CLLong | |
Show CLong | |
Show CPtrdiff | |
Show CSChar | |
Show CSUSeconds | |
Defined in GHC.Internal.Foreign.C.Types | |
Show CShort | |
Show CSigAtomic | |
Defined in GHC.Internal.Foreign.C.Types | |
Show CSize | |
Show CTime | |
Show CUChar | |
Show CUInt | |
Show CUIntMax | |
Show CUIntPtr | |
Show CULLong | |
Show CULong | |
Show CUSeconds | |
Show CUShort | |
Show CWchar | |
Show IntPtr | |
Show WordPtr | |
Show Associativity | @since base-4.6.0.0 |
Defined in GHC.Internal.Generics | |
Show DecidedStrictness | @since base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
Show Fixity | @since base-4.6.0.0 |
Show SourceStrictness | @since base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
Show SourceUnpackedness | @since base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
Show MaskingState | @since base-4.3.0.0 |
Defined in GHC.Internal.IO | |
Show SeekMode | @since base-4.2.0.0 |
Show CodingFailureMode | @since base-4.4.0.0 |
Defined in GHC.Internal.IO.Encoding.Failure | |
Show CodingProgress | @since base-4.4.0.0 |
Defined in GHC.Internal.IO.Encoding.Types | |
Show TextEncoding | @since base-4.3.0.0 |
Defined in GHC.Internal.IO.Encoding.Types | |
Show AllocationLimitExceeded | @since base-4.7.1.0 |
Defined in GHC.Internal.IO.Exception | |
Show ArrayException | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show AssertionFailed | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show AsyncException | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show BlockedIndefinitelyOnMVar | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show BlockedIndefinitelyOnSTM | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show CompactionFailed | @since base-4.10.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show Deadlock | @since base-4.1.0.0 |
Show ExitCode | |
Show FixIOException | @since base-4.11.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show IOErrorType | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show IOException | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show SomeAsyncException | @since base-4.7.0.0 |
Defined in GHC.Internal.IO.Exception | |
Show FD | @since base-4.1.0.0 |
Show HandlePosn | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Handle | |
Show FileLockingNotSupported | @since base-4.10.0.0 |
Defined in GHC.Internal.IO.Handle.Lock.Common | |
Show BufferMode | @since base-4.2.0.0 |
Defined in GHC.Internal.IO.Handle.Types | |
Show Handle | @since base-4.1.0.0 |
Show HandleType | @since base-4.1.0.0 |
Defined in GHC.Internal.IO.Handle.Types | |
Show Newline | @since base-4.3.0.0 |
Show NewlineMode | @since base-4.3.0.0 |
Defined in GHC.Internal.IO.Handle.Types | |
Show IOMode | @since base-4.2.0.0 |
Show IOPortException | |
Show InfoProv | |
Show Int16 | @since base-2.01 |
Show Int32 | @since base-2.01 |
Show Int64 | @since base-2.01 |
Show Int8 | @since base-2.01 |
Show CCFlags | @since base-4.8.0.0 |
Show ConcFlags | @since base-4.8.0.0 |
Show DebugFlags | @since base-4.8.0.0 |
Defined in GHC.Internal.RTS.Flags | |
Show DoCostCentres | @since base-4.8.0.0 |
Defined in GHC.Internal.RTS.Flags | |
Show DoHeapProfile | @since base-4.8.0.0 |
Defined in GHC.Internal.RTS.Flags | |
Show DoTrace | @since base-4.8.0.0 |
Show GCFlags | @since base-4.8.0.0 |
Show GiveGCStats | @since base-4.8.0.0 |
Defined in GHC.Internal.RTS.Flags | |
Show HpcFlags | @since base-4.20.0.0 |
Show IoSubSystem | |
Defined in GHC.Internal.RTS.Flags | |
Show MiscFlags | @since base-4.8.0.0 |
Show ParFlags | @since base-4.8.0.0 |
Show ProfFlags | @since base-4.8.0.0 |
Show RTSFlags | @since base-4.8.0.0 |
Show TickyFlags | @since base-4.8.0.0 |
Defined in GHC.Internal.RTS.Flags | |
Show TraceFlags | @since base-4.8.0.0 |
Defined in GHC.Internal.RTS.Flags | |
Show FractionalExponentBase | |
Defined in GHC.Internal.Real | |
Show StackEntry | |
Defined in GHC.Internal.Stack.CloneStack | |
Show CallStack | @since base-4.9.0.0 |
Show SrcLoc | @since base-4.9.0.0 |
Show StaticPtrInfo | @since base-4.8.0.0 |
Defined in GHC.Internal.StaticPtr | |
Show GCDetails | @since base-4.10.0.0 |
Show RTSStats | @since base-4.10.0.0 |
Show CBlkCnt | |
Show CBlkSize | |
Show CCc | |
Show CClockId | |
Show CDev | |
Show CFsBlkCnt | |
Show CFsFilCnt | |
Show CGid | |
Show CId | |
Show CIno | |
Show CKey | |
Show CMode | |
Show CNfds | |
Show CNlink | |
Show COff | |
Show CPid | |
Show CRLim | |
Show CSocklen | |
Show CSpeed | |
Show CSsize | |
Show CTcflag | |
Show CTimer | |
Show CUid | |
Show Fd | |
Show Lexeme | @since base-2.01 |
Show Number | @since base-4.6.0.0 |
Show SomeChar | |
Show SomeSymbol | @since base-4.7.0.0 |
Defined in GHC.Internal.TypeLits | |
Show SomeNat | @since base-4.7.0.0 |
Show GeneralCategory | @since base-2.01 |
Defined in GHC.Internal.Unicode | |
Show Word16 | @since base-2.01 |
Show Word32 | @since base-2.01 |
Show Word64 | @since base-2.01 |
Show Word8 | @since base-2.01 |
Show KindRep | |
Show Module | @since base-4.9.0.0 |
Show Ordering | @since base-2.01 |
Show TrName | @since base-4.9.0.0 |
Show TyCon | @since base-2.01 |
Show TypeLitSort | @since base-4.11.0.0 |
Defined in GHC.Internal.Show | |
Show Integer | @since base-2.01 |
Show Natural | @since base-4.8.0.0 |
Show () | @since base-2.01 |
Show Bool | @since base-2.01 |
Show Char | @since base-2.01 |
Show Int | @since base-2.01 |
Show Levity | @since base-4.15.0.0 |
Show RuntimeRep | @since base-4.11.0.0 |
Defined in GHC.Internal.Show | |
Show VecCount | @since base-4.11.0.0 |
Show VecElem | @since base-4.11.0.0 |
Show Word | @since base-2.01 |
Show a => Show (Complex a) Source # | Since: base-2.1 |
Show a => Show (First a) Source # | Since: base-4.9.0.0 |
Show a => Show (Last a) Source # | Since: base-4.9.0.0 |
Show a => Show (Max a) Source # | Since: base-4.9.0.0 |
Show a => Show (Min a) Source # | Since: base-4.9.0.0 |
Show m => Show (WrappedMonoid m) Source # | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
Show a => Show (NonEmpty a) | @since base-4.11.0.0 |
Show a => Show (And a) | @since base-4.16 |
Show a => Show (Iff a) | @since base-4.16 |
Show a => Show (Ior a) | @since base-4.16 |
Show a => Show (Xor a) | @since base-4.16 |
Show a => Show (Identity a) | This instance would be equivalent to the derived instances of the
@since base-4.8.0.0 |
Show a => Show (First a) | @since base-2.01 |
Show a => Show (Last a) | @since base-2.01 |
Show a => Show (Down a) | This instance would be equivalent to the derived instances of the
@since base-4.7.0.0 |
Show a => Show (Dual a) | @since base-2.01 |
Show a => Show (Product a) | @since base-2.01 |
Show a => Show (Sum a) | @since base-2.01 |
Show a => Show (ExceptionWithContext a) | |
Defined in GHC.Internal.Exception.Type | |
Show e => Show (NoBacktrace e) | |
Defined in GHC.Internal.Exception.Type | |
Show (ConstPtr a) | |
Show (ForeignPtr a) | @since base-2.01 |
Defined in GHC.Internal.ForeignPtr | |
Show a => Show (ZipList a) | @since base-4.7.0.0 |
Show p => Show (Par1 p) | @since base-4.7.0.0 |
Show (FunPtr a) | @since base-2.01 |
Show (Ptr a) | @since base-2.01 |
Show a => Show (Ratio a) | @since base-2.0.1 |
Show (SChar c) | @since base-4.18.0.0 |
Show (SSymbol s) | @since base-4.18.0.0 |
Show (SNat n) | @since base-4.18.0.0 |
Show a => Show (Maybe a) | @since base-2.01 |
Show a => Show (Solo a) | @since base-4.15 |
Show a => Show [a] | @since base-2.01 |
HasResolution a => Show (Fixed a) Source # | Since: base-2.1 |
(Show a, Show b) => Show (Arg a b) Source # | Since: base-4.9.0.0 |
(Ix a, Show a, Show b) => Show (Array a b) | @since base-2.01 |
(Show a, Show b) => Show (Either a b) | @since base-3.0 |
Show (Proxy s) | @since base-4.7.0.0 |
Show (TypeRep a) | |
Show (U1 p) | @since base-4.9.0.0 |
Show (V1 p) | @since base-4.9.0.0 |
Show (ST s a) | @since base-2.01 |
(Show a, Show b) => Show (a, b) | @since base-2.01 |
Show (a -> b) Source # | Since: base-2.1 |
Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
@since base-4.8.0.0 |
Show (f a) => Show (Ap f a) | @since base-4.12.0.0 |
Show (f a) => Show (Alt f a) | @since base-4.8.0.0 |
Show (Coercion a b) | @since base-4.7.0.0 |
Show (a :~: b) | @since base-4.7.0.0 |
Show (OrderingI a b) | |
Show (f p) => Show (Rec1 f p) | @since base-4.7.0.0 |
Show (URec Char p) | @since base-4.9.0.0 |
Show (URec Double p) | @since base-4.9.0.0 |
Show (URec Float p) | |
Show (URec Int p) | @since base-4.9.0.0 |
Show (URec Word p) | @since base-4.9.0.0 |
(Show a, Show b, Show c) => Show (a, b, c) | @since base-2.01 |
(Show (f a), Show (g a)) => Show (Product f g a) Source # | Since: base-4.18.0.0 |
(Show (f a), Show (g a)) => Show (Sum f g a) Source # | Since: base-4.18.0.0 |
Show (a :~~: b) | @since base-4.10.0.0 |
(Show (f p), Show (g p)) => Show ((f :*: g) p) | @since base-4.7.0.0 |
(Show (f p), Show (g p)) => Show ((f :+: g) p) | @since base-4.7.0.0 |
Show c => Show (K1 i c p) | @since base-4.7.0.0 |
(Show a, Show b, Show c, Show d) => Show (a, b, c, d) | @since base-2.01 |
Show (f (g a)) => Show (Compose f g a) Source # | Since: base-4.18.0.0 |
Show (f (g p)) => Show ((f :.: g) p) | @since base-4.7.0.0 |
Show (f p) => Show (M1 i c f p) | @since base-4.7.0.0 |
(Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) | @since base-2.01 |
(Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) | @since base-2.01 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) | @since base-2.01 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a, b, c, d, e, f, g, h) | @since base-2.01 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a, b, c, d, e, f, g, h, i) | @since base-2.01 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a, b, c, d, e, f, g, h, i, j) | @since base-2.01 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a, b, c, d, e, f, g, h, i, j, k) | @since base-2.01 |
(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 (a, b, c, d, e, f, g, h, i, j, k, l) | @since base-2.01 |
(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) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) | @since base-2.01 |
(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, Show n) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | @since base-2.01 |
(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, Show n, Show o) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | @since base-2.01 |
showChar :: Char -> ShowS Source #
utility function converting a Char
to a show function that
simply prepends the character unchanged.
showString :: String -> ShowS Source #
utility function converting a String
to a show function that
simply prepends the string unchanged.
showListWith :: (a -> ShowS) -> [a] -> ShowS Source #
Show a list (using square brackets and commas), given a function for showing elements.