Take the 2-minute tour ×

I can't find a tutorial or a good description anywhere. Can someone give me some pointers?

share|improve this question
0x00000000. It's the NULL pointer, so I wouldn't recommend traversing it, but there you go. :) –  Paul Sonier Jul 6 '11 at 17:20

4 Answers 4

Data.Typeable is an encoding of an well known approach (see e.g. Harper) to implementing delayed (dynamic) type checking in a statically typed language -- using a universal type.

Such a type wraps code for which type checking would not succeed until a later phase. Rather than reject the program as ill-typed, the compiler passes it on for runtime checking.

The style originated in Abadi et al., and developed for Haskell by Cheney and Hinze as a wrapper to represent all dynamic types, with the Typeable class appearing as part of the SYB work of SPJ and Lammel.


Even in the text books: dynamic types (with typeable representations) are statically typed languages with only one type, Harper ch 20:

enter image description here

share|improve this answer
"the untyped lambda calculus is really the uni-typed lambda calculus" - a beautiful pun! –  EarlGray Jan 17 '13 at 19:23

It's a library that allows, among other things, naming types. If a type a is declared Typeable, then you can get its name using show $ typeOf x where x is any value of type a. It also features limited type-casting.

(This is somewhat similar to C++'s RTTI or dynamic languages' reflection.)

share|improve this answer
No. Typeable does not allow casting, that's in Dynamic. And Dynamic does not allow casting between different types, because it forms a safe wrapper around unsafeCoerce. Typeable fits in as part of Dynamic's safe wrapper. It provides the ability to get a runtime representation of a type. Nothing more. –  Carl Jul 6 '11 at 20:20
@Carl: cast :: (Typeable a, Typeable b) => a -> Maybe b -- all you need is Typeable, no Dynamic involved! Using Typeable and cast you can in fact roll your own Dynamic fairly easily... –  sclv Jul 6 '11 at 20:46

One of the earliest descriptions I could find of a Data.Typeable-like library for Haskell is by John Peterson from 1992: http://www.cs.yale.edu/publications/techreports/tr1022.pdf

The earliest "official" paper I know of introducing the actual Data.Typeable library is the first Scrap Your Boilerplate paper from 2003: http://research.microsoft.com/en-us/um/people/simonpj/Papers/hmap/index.htm

I'm sure there's lots of intervening history that someone here can chime in with!

share|improve this answer

The Data.Typeable class is used primarily for generic programming in the Scrap Your Boilerplate (SYB) style. See also Data.Data

The idea is that SYB defines a collection combinators for performing operations such as printing, counting, searching, substiting, etc in a uniform manner over a variety of user-created types. The Typeable typeclass provides the necessary plumbing.

In modern GHC, you can just say deriving Data.Typeable when defining your own type in order to provide it with the necessary instances.

share|improve this answer

Your Answer


