<br><br><div class="gmail_quote">On Fri, Sep 25, 2009 at 10:55 PM, Casey Hawthorne <span dir="ltr"><<a href="mailto:caseyh@istar.ca">caseyh@istar.ca</a>></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>
>On Fri, Sep 25, 2009 at 8:14 PM, Job Vranish <<a href="mailto:jvranish@gmail.com">jvranish@gmail.com</a>> wrote:<br>
><br>
>> Supposedly OCaml has an OO feature that does this but I haven't tried it<br>
>> out.<br>
>><br>
><br>
>Indeed, OCaml has stuctural polymorphism, it's a wonderful feature.<br>
><br>
>*# let f myobj = myobj#foo "Hi !";;<br>
>val f : < foo : string -> 'a; .. > -> 'a = <fun>*<br>
><br>
>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'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's constructed and manipulated in a way which preserves the extra semantic rules.</div>
<div><br></div></div>-- <br>Sebastian Sylvan<br>