Can we simplify Dynamic?

David Feuer david.feuer at gmail.com
Mon Sep 28 22:14:39 UTC 2015


Sadly, I can't help with that. A while back I was doing something vaguely
"dynamic-like" but in a much more constrained context. I looked to
Data.Dynamic for inspiration and found horrors instead.
On Sep 28, 2015 6:11 PM, "Richard Eisenberg" <eir at cis.upenn.edu> wrote:

> And indeed it's  a good idea! And indeed it's happening!
>
> See, for example, https://ghc.haskell.org/trac/ghc/wiki/Typeable
> But that's now a bit out of date.
>
> Simon PJ, Dimitrios Vytiniotis, Stephanie Weirich and I are hard at work
> writing a paper about all of this, and we expect the results to be in GHC
> 8.0, with this Dynamic:
>
> data Dynamic where
>   Dynamic :: TypeRep a -> a -> Dynamic
>
> Note that TypeRep is now indexed. This is a breaking change, and I'll
> admit we haven't worked out the migration path. But we're focused on
> figuring out, precisely, where we're going before worrying too hard about
> how, precisely, we shall get there.
>
> But, a much better question from my standpoint is:
> Why do you care? Why do you use Dynamic? We're actually struggling a bit
> in the motivation section of the paper and would love to know why you care.
> :)
>
> Thanks!
> Richard
>
> On Sep 28, 2015, at 6:03 PM, Roman Cheplyaka <roma at ro-che.info> wrote:
>
> > I suggested this last year, see this thread
> > https://mail.haskell.org/pipermail/libraries/2014-March/022287.html
> >
> > On 09/29/2015 12:51 AM, David Feuer wrote:
> >> Currently,
> >>
> >> data Dynamic = Dynamic TypeRep Obj
> >>               deriving Typeable
> >> where
> >> type Obj = Any
> >>
> >> As a result, all of the operations must be implemented "by hand" using
> >> unsafeCoerce. The more obvious representation these days would seem to
> be
> >>
> >> data Dynamic where
> >>  Dynamic :: Typeable a => a -> Dynamic
> >>
> >> 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
> >>
> >> funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep
> >>
> >> from Data.Typeable to decide whether to coerce. It seems reasonable to
> >> add a more informative version, something like
> >>
> >> applyTypeable :: (Typeable f, Typeable a) =>
> >>   proxy f ->
> >>   proxy a ->
> >>   (forall b . (Typeable b, f ~ (a -> b)) => r) ->
> >>   Maybe r
> >>
> >> 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.
> >
> >
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150928/5286d19c/attachment.html>


More information about the Libraries mailing list