
#9429: Alternative to type family Any -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: 9097, 9380 None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by mboes): **Problem:** as mentioned in the description, `Any`-the-type-family does not admit a `Typeable` instance. `Any`-the-datatype does. We need a `Typeable` instance because `Any` is used as a proxy for type variables when invoking `typeOf` on a value at a polymorphic type. **Context:** rank1dynamic generalizes `Data.Typeable` to handle rank-1 polymorphic types, not just monotypes. This is useful because in Cloud Haskell one often expects a polymorphic function to be received. Any incoming function must be tagged with a representation of its type in order to compare it the expected type. rank1dynamic currently only handles types with quantified type variables of kind `*`. To make it handle types with quantified type variables of arbitrary kind, we instantiate all type variables with `Any` in order to get a monotype, for which we can get a `typeOf` can give us a runtime representation. Example: {{{ data Dict c = c => Dict return' :: Dict (Monad m) -> a -> m a type ANY1 = Any type ANY2 = Any Any tyreturn' = typeOf (return' :: Dict (Monad ANY1) -> ANY2) }}} this only works if `Any` has a `Typeable` instance. Otherwise, the `Typeable` constraint for the type written down in the signature cannot be satisfied. **Possible solutions:** 1. Hardcode a `Typeable` instance for `Any` in GHC, even though it is now a type family. 1. Reintroduce a new `Any`-the-datatype in the compiler, under a different name, and use that in `rank1dynamic` instead of GHC HEAD's `Any `-the-type-family. Restrict this `Any`-the-datatype to inhabit only open kinds, not closed kinds, in order to avoid #9380, #9097. 1. Same as previous solution, but don't bother with any restrictions on what kinds are inhabited. Consider this new `Any`-the-datatype *really- unsafe-use-at-your-own-risks*. Its use in rank1dynamic would be fine for types with no occurrences of closed type families. It would not work ok for more exotic types, but I don't think that would be a big deal in practice. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9429#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler