[Haskell-cafe] Unexpected Typeable behaviour; Prelude.undefined

Philip Holzenspies pkfh at st-andrews.ac.uk
Mon Aug 29 11:06:33 CEST 2011


Dear Brandon, Ozgur, et al,

Thanks very much for you explanation. This seems to be a perfectly reasonable explanation; the wrapper-types I used probably explicitly invoke typeOf with undefined. The problem here, however, is that in my actual program, I don't use ADTs, but I use GADTs, so as to carry the context (Monad, Typeable1) with the constructor. To get to this context, I must pattern-match with the constructor. It seems hiding contexts (which I really like about GADTs) isn't "available" consistently. Oh well ;)

Regards,
Philip


On 29 Aug 2011, at 01:20, Brandon Allbery wrote:

On Sun, Aug 28, 2011 at 18:44, Philip Holzenspies <pkfh at st-andrews.ac.uk<mailto:pkfh at st-andrews.ac.uk>> wrote:
instance (Typeable1 m, Monad m) => Typeable (MyADT m) where
       typeOf t@(MyADT _)

typeOf is usually invoked with an undefined parameter; it should use types, never values.  Here you've defined it to deconstruct what it's passed, which means that anything that uses it in the usual way (`typeOf (undefined :: someType)') will immediately throw undefined.

You don't need a deconstructor there; you (correctly) throw away the value, and it doesn't provide any type information not already available from the instance declaration.  `typeOf t' should be good enough.

--
brandon s allbery                                      allbery.b at gmail.com<mailto:allbery.b at gmail.com>
wandering unix systems administrator (available)     (412) 475-9364 vm/sms


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110829/6fef23e4/attachment.htm>


More information about the Haskell-Cafe mailing list