Proxy and new-typeable
Shachaf Ben-Kiki
shachaf at gmail.com
Fri Apr 19 08:43:41 CEST 2013
On Thu, Apr 18, 2013 at 11:56 AM, Richard Eisenberg <eir at cis.upenn.edu> wrote:
> Hi Ben,
>
> Oops. I had updated this page [http://hackage.haskell.org/trac/ghc/wiki/TypeLevelReasoning] 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.)
Shachaf
More information about the Libraries
mailing list