[GHC] #9429: Alternative to type family Any
GHC
ghc-devs at haskell.org
Mon Aug 18 08:03:41 UTC 2014
#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):
* If I declare `MyAny`, then as goldfire pointed out, it can only have a
kind of the form `-> *`. As it is, if rank1dynamic uses a datatype of
fixed kind, as for `MyAny`, then I will need many, many of those
datatypes, defined a priori. To handle multiple type variables, as in the
example given previously, I need a family `MyAny1`, `MyAny2`, `MyAny3`,
etc... Along an orthogonal dimension, to handle multiple kinds, I will
need multiple `MyAny`s, i.e. `MyAny1_s`, `MyAny1_ss`, `MyAny2_s`,
`MyAny2_ss`, etc (where `MyAny_s` is of kind `*`, `MyAny_ss` is o f kind
`* -> *`, etc). And even with that proliferation of datatypes, I still
wouldn't be able to handle type variables of user-defined kind, or even of
`Constraint` kind.
The beauty of the `Any` type in this use case is that because it inhabits
all kinds, I can use `Any` to instantiate the first type variable, `Any
Any` to instantiate the second, `Any Any Any` to instantiate the third,
etc. Moreover, I can still use those no matter the kinds of the type
variables. I only need a single datatype, to serve as a proxy for an
arbitrary number of type variables, each of arbitrary kind.
* A larger end-to-end example will take a little while to write, but I'll
try to do so tonight. At this point, if it can clarify things, let's just
say that any message that gets sent over the wire needs an accompanying
`TypeRep` of its type in order for the receiver to make sense of the
payload. Sometimes the payload is a function, and sometimes that function
is polymorphic and can be called by the receiver at any argument type. We
can't represent polymorphic types directly, so for a function of type
`forall a. a -> a`, we send the `TypeRep` for `Any -> Any` instead.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9429#comment:25>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list