Changes to Typeable
Edward Kmett
ekmett at gmail.com
Tue Feb 14 02:25:05 CET 2012
On Mon, Feb 13, 2012 at 3:27 PM, Simon Marlow <marlowsd at gmail.com> wrote:
> On 13/02/12 18:16, Edward Kmett wrote:
>
>> You could probably get away with something like
>>
>> data Proxy = Proxy a
>>
>> class Typeable a where
>> typeOfProxy :: Proxy a -> TypeRep
>>
>> typeOf :: forall a. Typeable a => a -> TypeRep
>> typeOf = typeOfProxy (Proxy :: Proxy a)
>>
>> which being outside of the class won't contribute to the inference of
>> 'a's kind.
>>
>> This would let you retain the existing functionality.
>>
>
> Simon's version has this:
>
> typeOf :: forall a. Typeable a => a -> TypeRep
> typeOf x = typeRep (getType x) where
> getType :: a -> Proxy a
> getType _ = Proxy
>
> (your version is clearer, though)
>
> I'm assuming there's no significance behind your renaming of 'typeRep' to
> 'typeOfProxy'?
>
No significance at all. I probably should have read the page before
commenting. ;)
-Edward
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20120213/f73cbf99/attachment-0001.htm>
More information about the Glasgow-haskell-users
mailing list