[Haskell-cafe] Read instance for constructors?
Semen Trygubenko / Семен Тригубенко
semen at trygub.com
Wed Mar 12 01:34:06 UTC 2014
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
> > 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.
Семен Тригубенко http://trygub.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Haskell-Cafe