Changes to Typeable

Dan Burton at
Fri Oct 5 18:04:41 CEST 2012

> Allowing users to write instances leads to potential un-soundness when
> doing dynamic type casts, so it has always been a Bad Idea.

Related to this, I'm sure several of us remember Bob Harper's blog post[1]
regarding exceptions that uses a hand-written Typeable instance. The ideal
scenario would be for the compiler to automatically derive Typeable for all
types, and completely disallow the user from providing hand-written
instances. To take advantage of Typeable, though, the user should still
have to annotate the necessary Typeable constraints. Whether this is
special-cased in the compiler for optimization is an implementation detail
and is largely irrelevant to the Haskell programmer; I say let's follow the
common Haskell mentality of making it correct first and fast second.

Most typeclasses come with some "laws" that make them useful; I don't see
any documented laws for Typeable, but presumably there are some (e.g. no
type should say it is another type), and the compiler can automatically
derive instances that are guaranteed to follow them.

It would be nice to be able to enforce typeclass laws on instances at
compile time, but that's stepping into theorem prover territory.


-- Dan Burton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list