I had never seen this work, it&#39;s just awesome !<br>And it only needs few Haskell extensions.<br><br>Is this work deeply documented somewhere except in research papers ? If not, it could be worth doing, IMO.<br><br><div class="gmail_quote">
On Tue, Sep 29, 2009 at 9:37 AM,  <span dir="ltr">&lt;<a href="mailto:oleg@okmij.org">oleg@okmij.org</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;">
<br>
Alp Mestan wrote:<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>
<br>
And Haskell has that too:<br>
<br>
&gt; -- This is how we define labels.<br>
&gt; data Field1 deriving Typeable; field1 = proxy::Proxy Field1<br>
&gt;<br>
&gt; -- This is how record selection looks like.<br>
&gt; foo f = f # field1<br>
<br>
The inferred type of  foo is<br>
<br>
        *OCamlTutorial&gt; :t foo<br>
        foo :: (HasField (Proxy Field1) r v) =&gt; r -&gt; v<br>
<br>
It doesn&#39;t seem too different from the OCaml&#39;s type; the type variable<br>
r acts as a row type.<br>
<br>
The quoted example is the first from many others described in<br>
        <a href="http://darcs.haskell.org/OOHaskell/OCamlTutorial.hs" target="_blank">http://darcs.haskell.org/OOHaskell/OCamlTutorial.hs</a><br>
<br>
The file quotes at length OCaml&#39;s Object tutorial and then<br>
demonstrates how the OCaml code can be written in Haskell.  When it<br>
comes to objects, structural subtyping, width and depth subtyping,<br>
etc., Haskell does not seem to miss match compared to OCaml. In<br>
contrast, Haskell has a few advantages when it comes to coercions<br>
(one does not have to specify the type to coerce to, as Haskell can<br>
figure that out). The other files in that directory give many more<br>
example of encoding C++, Eiffel, OCaml patterns.<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>Alp Mestan<br><a href="http://blog.mestan.fr/">http://blog.mestan.fr/</a><br><a href="http://alp.developpez.com/">http://alp.developpez.com/</a><br>