Data.Dynamic: Any vs existential

Edward Kmett ekmett at gmail.com
Mon Mar 10 20:18:39 UTC 2014


One reason for favoring the Proxy# a style over the Tagged style is almost
any manipulation of the Tagged variant requires ScopedTypeVariables and a
very awkward programming style, while a 0-width proxy can be passed around
like an explicit type application.

Otherwise they are largely equivalent if you're careful about how the low
level definitions work.

As the original author of both, I'm not personally wedded to either the
Tagged or the Proxy style, but I find in practice the Proxy version leads
to much prettier code that is easier to follow.

-Edward



On Mon, Mar 10, 2014 at 6:35 AM, Roman Cheplyaka <roma at ro-che.info> wrote:

> 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
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140310/05318940/attachment-0001.html>


More information about the Libraries mailing list