I think type witnesses <i>might</i> be relevant to your interests.<br><br><div class="gmail_quote">On Thu, Mar 25, 2010 at 11:13 AM, andy morris <span dir="ltr"><<a href="mailto:andy@adradh.org.uk">andy@adradh.org.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Can you have Typeable as an extra constraint? If so:<br>
<br>
> {-# LANGUAGE ExistentialQuantification #-}<br>
><br>
> import Data.Typeable<br>
><br>
> data Baz = forall a. (Eq a, Typeable a) => Baz a<br>
><br>
> instance Eq Baz where<br>
> Baz x == Baz y =<br>
> case cast y of<br>
> Just y' -> x == y'<br>
> Nothing -> False<br>
<br>
ghci> Baz 4 == Baz 4<br>
True<br>
ghci> Baz 4 == Baz 5<br>
False<br>
ghci> Baz 4 == Baz 'a'<br>
False<br>
<div><div></div><div class="h5"><br>
On 25 March 2010 15:07, Ozgur Akgun <<a href="mailto:ozgurakgun@gmail.com">ozgurakgun@gmail.com</a>> wrote:<br>
> Dear Cafe,<br>
><br>
> I need to use a language feature which is explicitly documented to be a<br>
> restriction, and -even worse- I think I reasonably need to use it.<br>
><br>
><br>
>> f2 (Baz1 a b) (Baz1 p q) = a==q<br>
>> It's ok to say a==b or p==q, but a==q is wrong because it equates the two<br>
>> distinct types arising from the two Baz1 constructors.<br>
>> [from 7.4.4.4. Restrictions at<br>
>> <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>
><br>
><br>
> To simplify, let's say Baz is the only constructor of a data type,<br>
><br>
> data Baz = forall a. Eq a => Baz a<br>
><br>
> -- | this cannot be done:<br>
> instance Eq (Baz a) where<br>
> (Baz x) == (Baz y) = x == y<br>
><br>
><br>
> I am quite tempted to use show functions for this equality comparison, but<br>
> after trying to have a nicely type framework I really don't want to do that.<br>
> What I simply want is, haskell to be able to compare them if they belong to<br>
> the same type, and return False otherwise. (not that haskelly way of doing<br>
> things, I know.)<br>
><br>
> Any suggestions better than the following are very welcome:<br>
> (==) = (==) `on` show<br>
><br>
><br>
> Regards,<br>
><br>
> --<br>
> Ozgur Akgun<br>
><br>
</div></div>> _______________________________________________<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>
><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><br clear="all"><br>-- <br> Alex R<br>