Looks great!<br><br>I started searching on how to write my own Typeable instances, but then I found the language extension <i>DeriveDataTypeable</i>, and now everything work like a charm.<br><br>Thanks very much!<br><br><div class="gmail_quote">
On 25 March 2010 15:13, andy morris <span dir="ltr">&lt;<a href="mailto:andy@adradh.org.uk">andy@adradh.org.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;">
Can you have Typeable as an extra constraint? If so:<br>
<br>
&gt; {-# LANGUAGE ExistentialQuantification #-}<br>
&gt;<br>
&gt; import Data.Typeable<br>
&gt;<br>
&gt; data Baz = forall a. (Eq a, Typeable a) =&gt; Baz a<br>
&gt;<br>
&gt; instance Eq Baz where<br>
&gt;   Baz x == Baz y =<br>
&gt;     case cast y of<br>
&gt;          Just y&#39; -&gt; x == y&#39;<br>
&gt;          Nothing -&gt; False<br>
<br>
ghci&gt; Baz 4 == Baz 4<br>
True<br>
ghci&gt; Baz 4 == Baz 5<br>
False<br>
ghci&gt; Baz 4 == Baz &#39;a&#39;<br>
False<br>
<div><div></div><div class="h5"><br>
On 25 March 2010 15:07, Ozgur Akgun &lt;<a href="mailto:ozgurakgun@gmail.com">ozgurakgun@gmail.com</a>&gt; wrote:<br>
&gt; Dear Cafe,<br>
&gt;<br>
&gt; I need to use a language feature which is explicitly documented to be a<br>
&gt; restriction, and -even worse- I think I reasonably need to use it.<br>
&gt;<br>
&gt;<br>
&gt;&gt; f2 (Baz1 a b) (Baz1 p q) = a==q<br>
&gt;&gt; It&#39;s ok to say a==b or p==q, but a==q is wrong because it equates the two<br>
&gt;&gt; distinct types arising from the two Baz1 constructors.<br>
&gt;&gt; [from 7.4.4.4. Restrictions at<br>
&gt;&gt; <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html" target="_blank">http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html</a>]<br>
&gt;<br>
&gt;<br>
&gt; To simplify, let&#39;s say Baz is the only constructor of a data type,<br>
&gt;<br>
&gt; data Baz = forall a. Eq a =&gt; Baz a<br>
&gt;<br>
&gt; -- | this cannot be done:<br>
&gt; instance Eq (Baz a) where<br>
&gt;     (Baz x) == (Baz y) = x == y<br>
&gt;<br>
&gt;<br>
&gt; I am quite tempted to use show functions for this equality comparison, but<br>
&gt; after trying to have a nicely type framework I really don&#39;t want to do that.<br>
&gt; What I simply want is, haskell to be able to compare them if they belong to<br>
&gt; the same type, and return False otherwise. (not that haskelly way of doing<br>
&gt; things, I know.)<br>
&gt;<br>
&gt; Any suggestions better than the following are very welcome:<br>
&gt;     (==) = (==) `on` show<br>
&gt;<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt; --<br>
&gt; Ozgur Akgun<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br><br clear="all"><br>-- <br>Ozgur Akgun<br>