da7df9b2919eeb06da94bed23ddf2b0bc44b387d
[ghc-base.git] / Text / Show.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  Text.Show
5 -- Copyright   :  (c) The University of Glasgow 2001
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  provisional
10 -- Portability :  portable
11 --
12 -- Converting values to readable strings:
13 -- the 'Show' class and associated functions.
14 --
15 -----------------------------------------------------------------------------
16
17 module Text.Show (
18    ShowS,               -- String -> String
19    Show(
20       showsPrec,        -- :: Int -> a -> ShowS
21       show,             -- :: a   -> String
22       showList          -- :: [a] -> ShowS 
23     ),
24    shows,               -- :: (Show a) => a -> ShowS
25    showChar,            -- :: Char -> ShowS
26    showString,          -- :: String -> ShowS
27    showParen,           -- :: Bool -> ShowS -> ShowS
28    showListWith,        -- :: (a -> ShowS) -> [a] -> ShowS 
29  ) where
30
31 #ifdef __GLASGOW_HASKELL__
32 import GHC.Show
33 #endif   
34
35 -- | Show a list (using square brackets and commas), given a function
36 -- for showing elements.
37 showListWith :: (a -> ShowS) -> [a] -> ShowS 
38 showListWith = showList__
39
40 #ifndef __GLASGOW_HASKELL__
41 showList__ :: (a -> ShowS) ->  [a] -> ShowS
42 showList__ _     []     s = "[]" ++ s
43 showList__ showx (x:xs) s = '[' : showx x (showl xs)
44   where
45     showl []     = ']' : s
46     showl (y:ys) = ',' : showx y (showl ys)
47 #endif