<br><br><div class="gmail_quote">On Fri, Sep 25, 2009 at 10:55 PM, Casey Hawthorne <span dir="ltr">&lt;<a href="mailto:caseyh@istar.ca">caseyh@istar.ca</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, 25 Sep 2009 23:25:21 +0200, you wrote:<br>
<br>
&gt;On Fri, Sep 25, 2009 at 8:14 PM, Job Vranish &lt;<a href="mailto:jvranish@gmail.com">jvranish@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Supposedly OCaml has an OO feature that does this but I haven&#39;t tried it<br>
&gt;&gt; out.<br>
&gt;&gt;<br>
&gt;<br>
&gt;Indeed, OCaml has stuctural polymorphism, it&#39;s a wonderful feature.<br>
&gt;<br>
&gt;*# let f myobj = myobj#foo &quot;Hi !&quot;;;<br>
&gt;val f : &lt; foo : string -&gt; &#39;a; .. &gt; -&gt; &#39;a = &lt;fun&gt;*<br>
&gt;<br>
&gt;IIRC, there has been work on Template Haskell for structural polymorphism.<br>
<br>
</div>Structural subtyping/polymorphism:<br>
<br>
Pros:<br>
- an object can be coerced to any compatible type, the types do not<br>
have to be specified ahead of time, that is at compile time.<br>
<br>
Cons:<br>
- may be overly permissive; some coercions might not make sense<br>
semantically.<br>
<br>
I wonder how Haskell will minimize the cons, since it is strongly<br>
typed.<br><br></blockquote><div><br></div><div>I kind of think there&#39;s no real problem here. If you say that you can accept any record with a given set of fields, then you have to make sure you make no other assumptions. This is, in principle, no different from passing a speed Double to a function that expects a mass Double (e.g. it may produce garbage for negative values). In both cases a function that requires extra invariants can enforce it by using a newtype that&#39;s constructed and manipulated in a way which preserves the extra semantic rules.</div>
<div><br></div></div>-- <br>Sebastian Sylvan<br>