<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 2009 Jan 23, at 8:37, Francesco Bochicchio wrote:</div><blockquote type="cite"><div class="gmail_quote"><div>I think I get the polymorphism. What I don't get is why a specialized type cannot</div> <div>replace a more generic type, since the specialized type implements the interface</div> <div>defined in the generic type.</div></div></blockquote><div><br></div><div>Try it this way. &nbsp;The declaration</div><div><br></div><div>> a :: Num n => n</div><div>> a = 3 :: Integer</div><div><br></div><div>is not the same as</div><br><blockquote type="cite"><div class="gmail_quote"><div> </div> <div>&nbsp;<span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">AbstractInterface&nbsp;a = new ConcreteClass();</span></div></div></blockquote><div><br></div><div>because Integer doesn't implement *all* of Num, in particular nothing needed for the Float, Double, or Complex instances. &nbsp;In a sense, instances in Haskell are inverses of interfaces in Java; in Java you accept more specific but in Haskell you accept *less* specific. &nbsp;This is because an instance actually asserts a "for all possible matching types" requirement, whereas Java asserts an "any matching type" requirement. &nbsp;(Pedantically:</div><div><br></div><div>> a :: forall n. Num n => n</div><div><br></div><div>You don't have to write (and in Haskell 98, can't write, just as in Java you can't explicitly write "forany" in an interface definition) the "forall"; in Haskell98 (and Java respectively) it's there by definition, in Haskell extensions it's implied for top level types for backward compatibility.)</div><div><br></div><div>In many cases you can treat the two the same because the member types happen to have an exact relationship such that "forall" and "forany" are both satisfied, but Num is too wide (and far too complex; the ideal structure of the Haskell numeric classes is constantly debated). &nbsp;So the equivalence of typeclasses and interfaces is a "most of the time" thing, not a definition or requirement.</div></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">--&nbsp;</span></span></font></div><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a href="mailto:allbery@kf8nh.com">allbery@kf8nh.com</a></span></span></font></div><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">system administrator [openafs,heimdal,too many hats] <a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a></span></span></font></div><div><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; ">electrical and computer engineering, carnegie mellon university &nbsp; &nbsp;KF8NH</span></span></font></div><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><br class="Apple-interchange-newline"></span></span></span></div></span> </div><br></body></html>