Proxy and new-typeable

Shachaf Ben-Kiki shachaf at
Fri Apr 19 09:06:10 CEST 2013

On Thu, Apr 18, 2013 at 11:55 PM, Roman Cheplyaka <roma at> wrote:
> * Shachaf Ben-Kiki <shachaf at> [2013-04-18 23:43:41-0700]
>> On Thu, Apr 18, 2013 at 11:56 AM, Richard Eisenberg <eir at> wrote:
>> > Hi Ben,
>> >
>> > Oops. I had updated this page [] with details but forgot to advertise. Pedro and I are scheduled to discuss next week, and I do hope that this get implemented/committed before April is out.
>> >
>> > Richard
>> >
>> There's another possible approach to the Proxy mess: Instead of using
>> or mentioning Proxy anywhere in the Typeable API, make Maybe the
>> "official" way to use typeRep.
>> The argument is something like: You want to get a TypeRep of a type,
>> but you may or may not have a value of that type. If you do, you pass
>> Just x. If you don't, you pass Nothing, annotated to the appropriate
>> type. A situation where you may or may not have a value is exactly
>> what Maybe is for, so it's not a hack. :-)
>> This is better than the Proxy approach because it lets typeRep have
>> the functionality of typeOf -- typeOf x = typeRep (Just x) -- which it
>> doesn't with plain Proxy. It's also better because Maybe is a Prelude
>> type suited to the purpose which everybody already knows.
>> (Of course typeRep can keep the polymorphic type, which would make it
>> Proxy-compatible. But we don't need to put Proxy in base, or re-export
>> it from Data.Typeable, or even mention it in the documentation.)
> I don't think it's possible. Proxy has to be kind-polymorphic, so that
> we can apply it to type constructors, constraints etc.
> But Maybe can't be kind-polymorphic, because it has a field of type 'a'.
> Thus, the kind of 'a' is forced to be *.
> Another problem with this approach is that it's not self-documenting.
> You have to say specifically that this argument is just a proxy and the
> semantics will be the same regardless of what you pass.
> But it was an interesting idea nevertheless.
> Roman

Bah, I hadn't thought of kind polymorphism. That's a problem -- though
is it a problem for any use of Typeable in base? Maybe the potential
for use is enough to justify exporting Proxy, though.

For the second point, at least the type of typeRep would be pretty
self-documenting, because it would be polymorphic in the "proxy" type,
not mention Maybe explicitly. Maybe you mean that use sites perhaps
wouldn't be? The situation wouldn't really be different from how
typeOf is used currently. But maybe that's not a good benchmark. Oh


More information about the Libraries mailing list