\documentclass{book}
\renewcommand{\chaptername}{Lecture}
\usepackage{amsmath}
\usepackage{ctable}
\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[breaklinks=true,unicode=true]{hyperref}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
%\setcounter{secnumdepth}{0}


\begin{document}

\setcounter{chapter}{13}

\chapter{Type classes}

Consider the following interaction with the \texttt{ghci}

\begin{verbatim}

GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> (+) 1

<interactive>:1:1:
    No instance for (Show (a0 -> a0))
      arising from a use of `print'
    Possible fix: add an instance declaration for (Show (a0 -> a0))
    In a stmt of an interactive GHCi command: print it
Prelude> (+) 1 2
3
Prelude>
\end{verbatim}
Here the interpreter is able to display the value \texttt{3} but not the
function \texttt{(+) 1}. The error message is instructive. It says that
there is no instance of \texttt{Show (a0 -\textgreater{} a0)} for use
with \texttt{print}. Let us see what \texttt{Show} and \texttt{print}
are by using the \texttt{:info} command of the interpreter.

\begin{verbatim}
$ ghci
GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :info Show
class Show a where
  showsPrec :: Int -> a -> ShowS
  show :: a -> String
  showList :: [a] -> ShowS
        -- Defined in GHC.Show
instance (Show a, Show b) => Show (Either a b)
  -- Defined in Data.Either
instance Show a => Show [a] -- Defined in GHC.Show
instance Show Ordering -- Defined in GHC.Show
instance Show a => Show (Maybe a) -- Defined in GHC.Show
instance Show Int -- Defined in GHC.Show
instance Show Char -- Defined in GHC.Show
instance Show Bool -- Defined in GHC.Show

[lots of similar lines delete]

Prelude> :info print
print :: Show a => a -> IO ()   -- Defined in System.IO
Prelude>
\end{verbatim}
To understand what it means we need to know how the interpreter behaves.
When even you enter an expression on the command line the interpreter
evaluates and tries to print it. However not all haskell types are
printable. The function \texttt{print} has the type
\texttt{Show a =\textgreater{} a -\textgreater{} IO ()} which means
\texttt{print} argument type \texttt{a} is not a general type variable
but is constranined to take types which are an instance of
\texttt{Show}. Here \texttt{Show} is a type class.

Note that from \texttt{:info Show} it is clear that the standard types
like \texttt{Int}, \texttt{Bool} etc are all instances of the class
\texttt{Show}. Therefore the interpreter could print any value of those
type. However, a function type is not an instance of \texttt{Show} and
hence could not be printed.

\end{document}
