Changes to Typeable

Emil Axelsson emax at chalmers.se
Mon Oct 15 07:58:12 CEST 2012


2012-10-14 14:34, Gábor Lehel skrev:
> So apologies for constantly suggesting new things, but if we have,
>
> - All Typeable instances for type constructors are generated by the
> compiler, and
> - All Typeable instances for composite types (if that's the word?) are
> via instance (Typeable f, Typeable a) => Typeable (f a), and
> - User-written instances, and therefore overlap, are disallowed,
>
> how difficult would it be to add:
>
> foo :: Typeable (f a) => Dict (Typeable f, Typeable a)
> -- data Dict c where Dict :: c => Dict c
>
> i.e. to make it possible to go in the other direction, and deduce that
> if a composite type is Typeable, its components must also be?
>
> (alternate encoding: foo :: Typeable (f a) => ((Typeable f, Typeable
> a) => r) -> r)
>
> Use case: nothing very serious, if it would take significant work,
> it's not worth it.

I have a use case:

 
http://hackage.haskell.org/packages/archive/syntactic/1.3/doc/html/Data-DynamicAlt.html

This is a reimplementation of Data.Dynamic to support casting type `a` 
to `Dynamic` given a constraint `Typeable (a -> b)`:

   toDyn :: Typeable (a -> b) => P (a -> b) -> a -> Dynamic

With your suggestion, it seems I should be able to use the ordinary 
Data.Dynamic instead.

/ Emil




More information about the Libraries mailing list