Down with Show!

Harry Garrood

Overview

  1. The problem with Show
  2. A replacement for Show, and what it gives us

What is wrong with Show?

Is it for:

  • Serialization?
  • Display, eg in a user interface?
  • Debugging / use in the repl?

Serialization

  • Show-serialized values will not be understood by non-Haskell programs
  • Inefficient
  • (Real World Haskell argues that Show is good for serialization!)
  • Better served by other serialization libraries

Display

  • Doesn't really make sense as an abstraction. Eg Parsec's error messages: "unexpected ')', expected new line or end of input"
  • Too many sensible implementations for some types, eg dates/times
  • Too easy to show the wrong thing
  • Impossible to change in a non-breaking way
  • Better served by individual functions

Debugging / the repl

  • Lots of types don't have instances: (->), IORef, IO
  • Poor display for large / complex values
  • No configurability in how printing is done
  • Better served by ...?

A replacement for Show

class Debug a where
  debug :: a -> Repr

To recap, it should:

  • explicitly only be for use in the repl and debugging
  • be possible to give every type of kind Type an instance
  • use a type with more structure than String
  • allow us to perform configurable pretty-printing in the repl