<br><br><div class="gmail_quote">On Fri, Oct 9, 2009 at 6:11 AM, pat browne <span dir="ltr">&lt;<a href="mailto:Patrick.Browne@comp.dit.ie">Patrick.Browne@comp.dit.ie</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
class Named object name | object -&gt; name where<br>
name :: object -&gt; name<br>
<br>
instance (Eq name, Named object name) =&gt; Eq object where<br>
object1 == object2 = (name object1) == (name object2)<br></blockquote><div><br>This is a type-indexed type.  On a modern GHC I would write it this way:<br><br>class Named a where<br>   type Name a<br>   name :: a -&gt; Name a<br>
<br>instance (Named a, Eq (Name a)) =&gt; Eq a where<br>   o1 == o2 = name o1 == name o2<br><br>Although to be honest I wouldn&#39;t write it this way at all, because your Eq instance is too general (remember, constraints are not examined when doing typeclass resolution; you are not saying &quot;every type &#39;a&#39; that is an instance of Named with Eq (Name a) is also an instance of Eq&quot;, you are saying &quot;EVERY type &#39;a&#39; is an instance of Eq, and please add the additional constraints &#39;Eq (Name a)&#39; and &#39;Named a&#39;&quot;) <br>
</div><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
My questions are:<br>
Question 1: Is my understanding correct?<br>
Question 2: What flavour of DT is this does this example exhibit?<br></blockquote><div><br></div></div>When you say &quot;Dependent Types&quot;, what is usually meant is that types can depend on *values*; for example:<br>
<br>data Vector :: Integer -&gt; * -&gt; * where<br>    Nil :: Vector 0 a<br>    Cons :: a -&gt; Vector n a -&gt; Vector (n+1) a<br><br>Now you might write this function:<br><br>zip :: forall a b. (n :: Integer) -&gt; Vector n a -&gt; Vector n b -&gt; Vector n (a,b)<br>
zip 0 Nil Nil = Nil<br>zip (n+1) (Cons x xs) (Cons y ys) = Cons (x,y) (zip n xs ys)<br><br>Notice that the *type* Vector n a depends on the *value* of the argument &#39;n&#39; passed in.  Normally it is only the other way around; values are limited by what type they are.  Here we have types being affected by some object&#39;s value!<br>
<br>  -- ryan<br>