The problem with hiding the context in the constructor is that there&#39;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) -&gt; m () -&gt; MyGADT m<br>
<br>instance (Typeable1 m, Monad m) =&gt; Typeable (MyGADT m) where<br>    typeof t = ...<br><br>getTypeRep :: MyGADT m -&gt; TypeRep<br>getTypeRep x@(MonadAction _) = typeof (undefined `asTypeOf` x)<br><br>Here we unpack the context from x and use it to construct the &#39;typeof&#39; 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">&lt;<a href="mailto:pkfh@st-andrews.ac.uk">pkfh@st-andrews.ac.uk</a>&gt;</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&#39;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&#39;t &quot;available&quot; 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">
&lt;<a href="mailto:pkfh@st-andrews.ac.uk" target="_blank">pkfh@st-andrews.ac.uk</a>&gt;</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) =&gt; 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&#39;ve defined it to deconstruct what it&#39;s passed, which means that anything that uses it in the usual way (`typeOf (undefined :: someType)&#39;) will immediately
 throw undefined.</div>
<div><br>
</div>
<div>You don&#39;t need a deconstructor there; you (correctly) throw away the value, and it doesn&#39;t provide any type information not already available from the instance declaration.  `typeOf t&#39; 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>