Can we simplify Dynamic?
Roman Cheplyaka
roma at ro-che.info
Mon Sep 28 22:03:46 UTC 2015
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150929/9dc2b4d0/attachment.sig>
More information about the Libraries
mailing list