I would happily supply a patch to add the Typeable (and the few Data instances that can be made) to transformers. I had to make similar ones in my comonad-transformers package anyways.<div><br></div><div>-Edward Kmett<br><br>
<div class="gmail_quote">On Wed, Feb 2, 2011 at 1:02 AM, John Millikin <span dir="ltr">&lt;<a href="mailto:jmillikin@gmail.com">jmillikin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Is there any reasonable way to do this if I want to cast a monadic<br>
value? For example:<br>
<br>
&gt; castState :: (Typeable a, Typeable s, Typeable1 m, Typeable b) =&gt; a -&gt; Maybe (StateT s m b)<br>
&gt; castState = Data.Typeable.cast<br>
<br>
None of the common monad transformers declare instances of Typeable,<br>
so I don&#39;t know if the concept itself even works.<br>
<br>
The use case here is one of my library users wants to return an<br>
Iteratee from code running in &quot;hint&quot;, which requires any extracted<br>
values be typeable. My first attempt at an extension-free instance is<br>
something like this:<br>
<br>
&gt; import Data.Enumerator<br>
&gt; import Data.Typeable<br>
&gt;<br>
&gt; instance (Typeable a, Typeable1 m) =&gt; Typeable1 (Iteratee a m) where<br>
&gt;       typeOf1 i = rep where<br>
&gt;               typed :: (a -&gt; b) -&gt; b -&gt; a -&gt; a<br>
&gt;               typed _ _ a = a<br>
&gt;<br>
&gt;               ia :: a -&gt; Iteratee a m b<br>
&gt;               ia = undefined<br>
&gt;<br>
&gt;               im :: m c -&gt; Iteratee a m b<br>
&gt;               im = undefined<br>
&gt;<br>
&gt;               rep = mkTyConApp (mkTyCon &quot;Data.Enumerator.Iteratee&quot;) [tyA, tyM]<br>
&gt;               tyA = typeOf (typed ia i undefined)<br>
&gt;               tyM = typeOf1 (typed im i undefined)<br>
<br>
which, besides being ugly, I have no idea if it&#39;s correct.<br>
<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>
</blockquote></div><br></div>