<div dir="ltr">the tricky part then is to add support for other types.<div><br></div><div>another approach to existentially package type classes with the data type!</div><div><br></div><div style>eg </div><div style>data HasEq  = forall a . HasEq ( Eq a =&gt; a)</div>

<div style>or its siblinng</div><div style>data HasEq a = Haseq (Eq a =&gt; a )</div><div style><br></div><div style>note this requires more planning in how you structure your program, but is a much more pleasant approach than using dynamic when you can get it to suite your application needs.</div>

<div style><br></div><div style>note its also late, so I&#39;ve not type checked these examples ;)</div><div style><br></div><div style>-Carter</div><div style> <br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Fri, Jul 19, 2013 at 12:54 PM, adam vogt <span dir="ltr">&lt;<a href="mailto:vogt.adam@gmail.com" target="_blank">vogt.adam@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">

<div class="im">On Fri, Jul 19, 2013 at 5:19 AM, Jose A. Lopes &lt;<a href="mailto:jabolopes@google.com">jabolopes@google.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; How to define equality for Data.Dynamic ?<br>
<br>
</div>Hi Jose,<br>
<br>
You could try casting the values to different types that do have an<br>
(==). You can treat the case where you have the types matching, but<br>
didn&#39;t list that type beforehand differently.<br>
<br>
<br>
eqTys a b<br>
    | Just a&#39; &lt;- fromDynamic a, Just b&#39; &lt;- fromDynamic b = a&#39; == (b&#39; :: Int)<br>
    | Just a&#39; &lt;- fromDynamic a, Just b&#39; &lt;- fromDynamic b = a&#39; == (b&#39; :: Integer)<br>
    | show a == show b = error &quot;equal types, but don&#39;t know if there&#39;s an (==)!&quot;<br>
    | otherwise = False<br>
<br>
<br>
{-<br>
<br>
&gt; eqTys (toDyn 4) (toDyn 5)<br>
False<br>
<br>
&gt; eqTys (toDyn 4) (toDyn 4)<br>
True<br>
<br>
&gt; eqTys (toDyn 4) (toDyn 4.5)<br>
False<br>
<br>
&gt; eqTys (toDyn 4.5) (toDyn 4.5)<br>
*** Exception: equal types, but don&#39;t know if there&#39;s an (==)!<br>
<br>
-}<br>
<br>
<br>
--<br>
Adam<br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>