Data.Dynamic: Any vs existential

Simon Peyton Jones simonpj at microsoft.com
Mon Mar 10 11:26:42 UTC 2014


Dear Core Libraries committee

I think Roman is right here. Moreover we have known this for at least I think seven years
http://comments.gmane.org/gmane.comp.lang.haskell.cafe/20097, where I wrote:

| Yes, Dynamic preceded the Typeable class, I think.  
| Were we to do it today, I think we'd have
|
| data Dynamic = forall a . (Typeable a) => Dynamic a
|
| Whether it's worth changing, I'm not sure.  It's a library so, 
| if a change desirable, anyone could take a lead.

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.

Pedro is the most recent visitor to this territory and may have views.

Roman's point about the method for the Typeable class is a good one too, and not one I've seen discussed.

Over to you

Simon

| -----Original Message-----
| From: Libraries [mailto:libraries-bounces at haskell.org] On Behalf Of
| Roman Cheplyaka
| Sent: 10 March 2014 10:35
| To: libraries at haskell.org
| Subject: Re: Data.Dynamic: Any vs existential
| 
| Ok, one reason is that the TypeRep won't be cached in the Dynamic value.
| Even in GHC 7.8 Typeable is defined as
| 
|   class Typeable a where
|     typeRep# :: Proxy# a -> TypeRep
| 
| instead of
| 
|   class Typeable a where
|     typeRep :: Tagged a TypeRep
| 
| Why? Is this an oversight?
| 
| * Roman Cheplyaka <roma at ro-che.info> [2014-03-10 12:11:27+0200]
| > In Data.Dynamic, Dynamic is defined as
| >
| >   data Dynamic = Dynamic TypeRep Any
| >
| > Does this have any advantage over a safer
| >
| >   data Dynamic = forall a. Typeable a => Dynamic a
| >
| > ?
| >
| > Roman


More information about the Libraries mailing list