<div dir="ltr"><div class="gmail_extra">On Mon, Mar 10, 2014 at 7:26 AM, Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Core Libraries committee<br>
<br>
I think Roman is right here. Moreover we have known this for at least I think seven years<br>
<a href="http://comments.gmane.org/gmane.comp.lang.haskell.cafe/20097" target="_blank">http://comments.gmane.org/gmane.comp.lang.haskell.cafe/20097</a>, where I wrote:<br>
<br>
| Yes, Dynamic preceded the Typeable class, I think.<br>
| Were we to do it today, I think we'd have<br>
|<br>
| data Dynamic = forall a . (Typeable a) => Dynamic a<br>
|<br>
| Whether it's worth changing, I'm not sure.  It's a library so,<br>
| if a change desirable, anyone could take a lead.<br>
<br>
The new representation for Dynamic would be good because it's less insecure than all this "Obj" nonsense, instead relying on Typeable, which is pretty good these days.<br>
<br>
Pedro is the most recent visitor to this territory and may have views.<br>
<br>
Roman's point about the method for the Typeable class is a good one too, and not one I've seen discussed.<br>
<br>
Over to you<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">I, at least, am in favor of this. I've thought for a while that the ideal form of all this is something like:<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">    data TypeRep a -- indexed by a<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">
    class Typeable a where<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">      typeRep :: TypeRep a<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">
    data Dynamic = forall a. Dynamic (TypeRep a) a</div> </div></div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Where, ideally, TypeRep is an indexed type, and you can match on it to refine its argument. Then Typeable just becomes the implicit version of this evidence, for convenience. TypeRep versions of cast would also have to be primitive probably (since one can not, a priori, enumerate the diagonal of all possible monotypes, now and in the future).<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Anyhow, I don't know if this entire interface is or will be implementable in GHC (the idea comes from a document about JHC way back, although I don't know if even it implements this), but using Typeable in an existential captures the Dynamic part of it, at least.<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Also, I hadn't seen the Tagged version of Typeable before (and hadn't thought of it myself). I expect it's an oversight that this wasn't the form chosen, as it seems superior to me. In fact, it seems like every situation where the 0-width Proxy# could be used, Tagged could also be used instead, and is automatically 0-width, and has better sharing behavior? Unless you explicitly don't want sharing, that is.<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">It seems like any relative inconvenience could probably be alleviated by the proxy function in tagged, while keeping the nicer behavior.<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">-- Dan<br></div></div></div>