<p dir="ltr">Currently,</p>
<p dir="ltr">data Dynamic = Dynamic TypeRep Obj<br>
               deriving Typeable<br>
where<br>
type Obj = Any</p>
<p dir="ltr">As a result, all of the operations must be implemented "by hand" using unsafeCoerce. The more obvious representation these days would seem to be</p>
<p dir="ltr">data Dynamic where<br>
  Dynamic :: Typeable a => a -> Dynamic</p>
<p dir="ltr">Most of the operations then become trivial applications of Typeable functions.    The only exceptions seem to be  dynApply and dynApp. That there are exceptions strikes me as quite unfortunate. The easiest fix is inspired by the fact that Data.Dynamic uses</p>
<p dir="ltr">funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep</p>
<p dir="ltr">from Data.Typeable to decide whether to coerce. It seems reasonable to add a more informative version, something like</p>
<p dir="ltr">applyTypeable :: (Typeable f, Typeable a) =><br>
   proxy f -><br>
   proxy a -><br>
   (forall b . (Typeable b, f ~ (a -> b)) => r) -><br>
   Maybe r</p>
<p dir="ltr">On the other hand, it would be really cool if there were some more general way to get type-level information out of Typeable instances, pattern matching on the type constructors.</p>