\begin{code}
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
-- |
-- Module : GHC.Show
--
-----------------------------------------------------------------------------
+-- #hide
module GHC.Show
(
Show(..), ShowS,
)
where
-import {-# SOURCE #-} GHC.Err ( error )
import GHC.Base
-import GHC.Enum
import Data.Maybe
import Data.Either
-import GHC.List ( (!!),
+import GHC.List ( (!!), foldr1
#ifdef USE_REPORT_PRELUDE
- , concatMap, foldr1
+ , concatMap
#endif
)
\end{code}
-- \s -> showChar '(' (sx (showChar ',' (sy (showChar ')' s))))
instance (Show a, Show b) => Show (a,b) where
- showsPrec _ (x,y) s = (showChar '(' . shows x . showChar ',' .
- shows y . showChar ')')
- s
+ showsPrec _ (a,b) s = show_tuple [shows a, shows b] s
instance (Show a, Show b, Show c) => Show (a, b, c) where
- showsPrec _ (x,y,z) s = (showChar '(' . shows x . showChar ',' .
- shows y . showChar ',' .
- shows z . showChar ')')
- s
+ showsPrec _ (a,b,c) s = show_tuple [shows a, shows b, shows c] s
instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) where
- showsPrec _ (w,x,y,z) s = (showChar '(' . shows w . showChar ',' .
- shows x . showChar ',' .
- shows y . showChar ',' .
- shows z . showChar ')')
- s
+ showsPrec _ (a,b,c,d) s = show_tuple [shows a, shows b, shows c, shows d] s
instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) where
- showsPrec _ (v,w,x,y,z) s = (showChar '(' . shows v . showChar ',' .
- shows w . showChar ',' .
- shows x . showChar ',' .
- shows y . showChar ',' .
- shows z . showChar ')')
- s
+ showsPrec _ (a,b,c,d,e) s = show_tuple [shows a, shows b, shows c, shows d, shows e] s
+
+instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where
+ showsPrec _ (a,b,c,d,e,f) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f] s
+
+instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g)
+ => Show (a,b,c,d,e,f,g) where
+ showsPrec _ (a,b,c,d,e,f,g) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i,j) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i, shows j] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i,j,k) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i, shows j, shows k] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i, shows j, shows k, shows l] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i, shows j, shows k, shows l, shows m] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i, shows j, shows k, shows l, shows m, shows n] s
+
+instance (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) where
+ showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) s
+ = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
+ shows i, shows j, shows k, shows l, shows m, shows n, shows o] s
+
+show_tuple :: [ShowS] -> ShowS
+show_tuple ss = showChar '('
+ . foldr1 (\s r -> s . showChar ',' . r) ss
+ . showChar ')'
\end{code}
itos :: Int# -> String -> String
itos n# cs
- | n# <# 0# = let
- n'# = negateInt# n#
- in if n'# <# 0# -- minInt?
- then '-' : itos' (negateInt# (n'# `quotInt#` 10#))
- (itos' (negateInt# (n'# `remInt#` 10#)) cs)
- else '-' : itos' n'# cs
+ | n# <# 0# =
+ let I# minInt# = minInt in
+ if n# ==# minInt#
+ -- negateInt# minInt overflows, so we can't do that:
+ then '-' : itos' (negateInt# (n# `quotInt#` 10#))
+ (itos' (negateInt# (n# `remInt#` 10#)) cs)
+ else '-' : itos' (negateInt# n#) cs
| otherwise = itos' n# cs
where
itos' :: Int# -> String -> String
| otherwise = case chr# (ord# '0'# +# (n# `remInt#` 10#)) of { c# ->
itos' (n# `quotInt#` 10#) (C# c# : cs) }
\end{code}
+
+%*********************************************************
+%* *
+\subsection{Other instances}
+%* *
+%*********************************************************
+
+\begin{code}
+instance Show Unknown where
+ show _ = "This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type"
+ showList _ = ("This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type" ++)
+
+instance Show (Unknown1 a) where
+ show _ = "This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type"
+ showList _ = ("This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type" ++)
+
+instance Show (Unknown2 a b) where
+ show _ = "This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type"
+ showList _ = ("This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type" ++)
+
+instance Show (Unknown3 a b c) where
+ show _ = "This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type"
+ showList _ = ("This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type" ++)
+
+instance Show (Unknown4 a b c d) where
+ show _ = "This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type"
+ showList _ = ("This is an untyped, unevaluated computation. You can use seq to force its evaluation and then :print to recover its type" ++)
+
+\end{code}
\ No newline at end of file