[Haskell-cafe] Don't make 'show*' functions

Jonathan Cast jonathanccast at fastmail.fm
Fri Dec 26 14:31:02 EST 2008

On Fri, 2008-12-26 at 11:51 +0000, Thomas DuBuisson wrote:
> Hello cafe,
> This is just a small thought, but its been bugging me.  We have these
> things called type classes for a reason (I like to think).

Type classes were invented for two reasons:

1) To imitate mathematical convention.  Addition, in full, is written as

  x +_{A} y

where A is a mathematical structure supplying addition.  However, the
convention is that the subscript may be omitted `when no ambiguity may
arise'.  Programming languages (generally) take this and run with it,

  x + y

to mean (depending on the language) pretty much anything.  Type classes
are an ingenious step back toward the mathematical convention, where the
operation + must come from some complete structure.

2) To allow conversion from structured data into strings to be treated
as a single operation.  Most languages support this in some form, but I
am increasingly failing to see why.  There are usually several different
ways in which a given piece of structured data can meaningfully be
`shown'; in languages which try to do the right thing when given

  print "string", 'c', (2 + 2), [true, false, :maybe]

you *still* end up defining (multiple!) special-purpose output or
conversion-to-string functions so you can print the same data in
multiple ways.  I think making Show a type class was a mistake.


More information about the Haskell-Cafe mailing list