[Haskell-cafe] Read instance for constructors?

Semen Trygubenko / Семен Тригубенко semen at trygub.com
Wed Mar 12 01:34:06 UTC 2014


Dear Niklas,

On Wed, Mar 12, 2014 at 01:10:19AM +0100, Niklas Haas wrote:
> Oops, sorry, that was supposed to have been:
> 
> > dataTypeOf :: Data a => Proxy a -> DataType
> or
> > dataTypeOf :: Data a => p a -> DataType
> 
> As for the implementation, the simplest possible (ie. no language
> extensions) implementation I can think of looks like this:
> 
> > dataTypeOf = Data.dataTypeOf . f
> >   where f :: p a -> a
> >         f _ = error "dataTypeOf: this should never be used"
> 
> where Data.dataTypeOf refers to the ‘original’ version of that function.

Awesomeness! I see now what you meant by Proxy and
that Data.dataTypeOf doesn't even get evaluated, i.e. its sole purpose is to
ferry the type information across… Neat.

Much obliged,
S.


-- 
Семен Тригубенко http://trygub.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140312/a0171a8c/attachment.sig>


More information about the Haskell-Cafe mailing list