<br><br><div class="gmail_quote">On Fri, Oct 9, 2009 at 6:11 AM, pat browne <span dir="ltr"><<a href="mailto:Patrick.Browne@comp.dit.ie">Patrick.Browne@comp.dit.ie</a>></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 -> name where<br>
name :: object -> name<br>
<br>
instance (Eq name, Named object name) => 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 -> Name a<br>
<br>instance (Named a, Eq (Name a)) => Eq a where<br> o1 == o2 = name o1 == name o2<br><br>Although to be honest I wouldn'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 "every type 'a' that is an instance of Named with Eq (Name a) is also an instance of Eq", you are saying "EVERY type 'a' is an instance of Eq, and please add the additional constraints 'Eq (Name a)' and 'Named a'") <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 "Dependent Types", what is usually meant is that types can depend on *values*; for example:<br>
<br>data Vector :: Integer -> * -> * where<br> Nil :: Vector 0 a<br> Cons :: a -> Vector n a -> Vector (n+1) a<br><br>Now you might write this function:<br><br>zip :: forall a b. (n :: Integer) -> Vector n a -> Vector n b -> 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 'n' 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's value!<br>
<br> -- ryan<br>