<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Allowing users to write instances leads to potential un-soundness when doing dynamic type casts, so it has always been a Bad Idea.<br>

</blockquote><div><br></div><div>Related to this, I&#39;m sure several of us remember Bob Harper&#39;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&#39;s follow the common Haskell mentality of making it correct first and fast second.</div>

<div><br></div><div>Most typeclasses come with some &quot;laws&quot; that make them useful; I don&#39;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.</div>

<div><br></div><div>It would be nice to be able to enforce typeclass laws on instances at compile time, but that&#39;s stepping into theorem prover territory.</div><div><br></div><div>[1] <a href="http://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/">http://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/</a></div>

<div><br></div><div>-- Dan Burton</div></div>