The problem with hiding the context in the constructor is that there's no guarantee that the context actually exists in the first place; for example, given this type<br><br>data IsInt a where<br> Proof :: IsInt Int<br>
<br>this is a legal program:<br><br>foo :: IsInt Bool<br>foo = undefined<br><br>That said, you are still just fine to hide the context in the constructor at the call site:<br><br>data MyGADT m where<br> MonadAction :: (Typeable1 m, Monad m) -> m () -> MyGADT m<br>
<br>instance (Typeable1 m, Monad m) => Typeable (MyGADT m) where<br> typeof t = ...<br><br>getTypeRep :: MyGADT m -> TypeRep<br>getTypeRep x@(MonadAction _) = typeof (undefined `asTypeOf` x)<br><br>Here we unpack the context from x and use it to construct the 'typeof' function for MyGADT m.<br>
<br> -- ryan<br><br><div class="gmail_quote">On Mon, Aug 29, 2011 at 2:06 AM, Philip Holzenspies <span dir="ltr"><<a href="mailto:pkfh@st-andrews.ac.uk">pkfh@st-andrews.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="word-wrap: break-word;">
Dear Brandon, Ozgur, et al,
<div><br>
</div>
<div>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 ;)</div>
<div><br>
</div>
<div>Regards,</div>
<div>Philip</div><div><div></div><div class="h5">
<div><br>
</div>
<div><br>
<div>
<div>On 29 Aug 2011, at 01:20, Brandon Allbery wrote:</div>
<br>
<blockquote type="cite">
<div dir="ltr">On Sun, Aug 28, 2011 at 18:44, Philip Holzenspies <span dir="ltr">
<<a href="mailto:pkfh@st-andrews.ac.uk" target="_blank">pkfh@st-andrews.ac.uk</a>></span> wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
instance (Typeable1 m, Monad m) => Typeable (MyADT m) where<br>
typeOf t@(MyADT _)<br>
</blockquote>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
</div>
-- <br>
brandon s allbery <a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a><br>
wandering unix systems administrator (available) <a href="tel:%28412%29%20475-9364" value="+14124759364" target="_blank">(412) 475-9364</a> vm/sms<br>
<br>
</div>
</blockquote>
</div>
<br>
</div>
</div></div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>