Proxy and new-typeable

Shachaf Ben-Kiki shachaf at
Sat Jan 26 05:07:10 CET 2013

I see that the new-typeable branch in GHC is using "typeRep :: forall a.
Typeable a => Proxy a -> TypeRep" rather than "typeOf :: forall a. Typeable a
=> a -> TypeRep". This is clearly a big improvement over using undefined

I'd like to suggest a small change, if it hasn't been brought up before --
"typeRep :: forall proxy a. Typeable a => proxy a -> TypeRep". This makes
typeRep compatible with any other Proxy type, since it doesn't use any
properties of the concrete type -- it just uses it to pass information about
the "a". Things that consume a Proxy don't ever need to refer to Proxy

This would make Typeable compatible with other Proxy libraries, like the one in
"tagged". It would also make it compatible with any other type of kind * -> *
-- for example, "typeRep ([] :: [Int])" would be a valid, and arguable more
convenient, syntax for using typeRep. "Nothing :: Maybe Int" and so on would
work too. So things that produce a "proxy" don't need to refer to Proxy
explicitly either.

Possibly this would make the Proxy type entirely unnecessary. If it stays,
though, I suggest that it belongs in a module other than Data.Typeable.Internal
-- it's a useful type for many other things, and as long as it's in base and
exposed to users, it might as well be treated as a type in its own right. It's
also a monad, can provide a variant of `asTypeOf`, and so on.


More information about the Libraries mailing list