ZVON > References > Haskell reference
| Indexes | Syntax | >> Prelude << | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Module: Prelude
Class: Show
Instances: (), [a], Char, Double, Float, Int, Integer
Bibliography: The Read and Show Classes [ A Gentle Introduction to Haskell ]


class  Show a  where
    showsPrec        :: Int -> a -> ShowS
    show       :: a -> String 
    showList         :: [a] -> ShowS

-- Mimimal complete definition:
-- show or showsPrec
    showsPrec _ x s   = show x ++ s

    show x        = showsPrec 0 x ""

    showList []       = showString "[]"
    showList (x:xs)   = showChar '[' . shows x . showl xs
                        where showl []     = showChar ']'
                              showl (x:xs) = showChar ',' . shows x .
                                             showl xs



instance Show Int where

    showsPrec           = showSigned showInt

instance Show Integer where

    showsPrec           = showSigned showInt

instance Show Float where
 
    showsPrec p         = showFloat

instance Show Double where

    showsPrec p         = showFloat

instance Show () where

    showsPrec p () = showString "()"

instance Show Char where

    showsPrec p '\'' = showString "'\\''"
    showsPrec p c    = showChar '\'' . showLitChar c . showChar '\''

    showList cs = showChar '"' . showl cs
                 where showl ""       = showChar '"'
                       showl ('"':cs) = showString "\\\"" . showl cs
                       showl (c:cs)   = showLitChar c . showl cs

instance (Show a) => Show [a] where

    showsPrec p      = showList