[Started work on new examples John Goerzen **20070611031745] { hunk ./en/ch05-typeclasses.xml 246 - FIXME + Now that you're familiar with defining your own typeclasses and making + your types instances of typeclasses, it's time to introduce you to + typeclasses that are a standard part of Haskell. As we mentioned at + the beginning of this chapter, typeclasses are at the core of some + imporant aspects of the language. We'll cover the most common ones + here. hunk ./en/ch05-typeclasses.xml 254 - - Read and Show + + Show + + The Show typeclass is used to convert types to + Strings. It is perhaps most commonly used to + convert numbers to Strings, but it is defined for + so many types that it can be used to convert quite a bit more. You + can also, of course, define instances for your own types as well. + + + The most important function of Show is + show. It takes one argument: the type to convert. + It returns a String representing that type. + + + Here is an example usage, from taken from a quick session with ghci: + + + + + Read addfile ./examples/ch05/show.ghci hunk ./examples/ch05/show.ghci 1 +--# typetwiddle +show 1 +show [1, 2, 3] +show (1, 2) +show "Hello!" +putStrLn (show "Hello!") +show ['H', 'i'] +putStrLn (show "Hi") +show "Hi, \"Jane\"" +putStrLn (show "Hi, \"Jane\"") }