Alternative to type family Any
In GHC HEAD, Any
is no longer a datatype. There are good reasons for this change, one of which was explained in #9097 (closed), the original ticket, and another in #9380 (closed). Unfortunately, a casualty of this change is that it is no longer easy to generalize the rank1dynamic package to rank-1 types with type variables of arbitrary kind (not just *
). We submitted a way to do so here, that exploits the fact that Any
has the very magical property of inhabiting *all* kinds, including closed ones.
This works for GHC 7.8, but won't work in HEAD, because we require that there exists a Typeable
instance for Any
, just as there are Typeable
instances for any other type one wishes to have instances for. The reason is that now that Any
is a type family, Any
is no longer a legal instance head.
There are several possible solutions that I see:
- while it's clearly dangerous for the compiler to be inserting the old
Any
during typechecking from the moment that we have computation in types over closed kinds, we may still want the oldAny
, say under a different name, as a backdoor. It wouldn't be used by the compiler during type checking - only by packages such as rank1dynamic. I believe that furthermore, if we restrict the oldAny
to not inhabit closed kinds, then none of the problems cited in the above tickets arise. - Instead of making the new
Any
a type family, keep it a datatype, but ban it from inhabiting closed kinds. I don't know if such anAny
would be sufficient for the purposes of GHC, however. - Hardwire a
Typeable
instance for theAny
type family (not sure if this makes sense).