<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/01/be4cf6635106b2ef386963204ac08a99"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-01-10T03:45:45"
  subject="Re: [Caml-list] record declaration, SML"
  prev="2003/01/d2c4dfd25d1b050470452b5a3c62be39"
  next="2003/01/277d23fbd8d964d99d8b80b7f032590a"
  prev-in-thread="2003/01/5139d8a47eedbc92eee9fe549d84283c"
  next-in-thread="2003/01/e1fc2cb6dafc061afc5f6f4faf822561"
  prev-thread="2003/01/37bde005f875aa75e55ca6ee21ec7ede"
  next-thread="2003/01/277d23fbd8d964d99d8b80b7f032590a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] record declaration, SML">
<msg 
  url="2003/01/3eeaa34f72ab83397e790fabbb1b7306"
  from="A. Ozmen &lt;aoz@d...&gt;"
  author="A. Ozmen"
  date="2003-01-09T18:04:44"
  subject="[Caml-list] record declaration, SML">
<msg 
  url="2003/01/9948de611fa2a519a7c4aa54234716d9"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-01-09T18:28:00"
  subject="Re: [Caml-list] record declaration, SML">
<msg 
  url="2003/01/78b896e07d18240e06adb3dd5c3c7870"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-01-10T09:21:17"
  subject="Re: [Caml-list] record declaration, SML">
<msg 
  url="2003/01/93b1291528684957aead21b72f0a9544"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-01-10T14:34:43"
  subject="Re: [Caml-list] record declaration, SML">
</msg>
</msg>
<msg 
  url="2003/01/f9c3d99bba40e8cf1b94eb7cb5777c81"
  from="A. Ozmen &lt;aoz@d...&gt;"
  author="A. Ozmen"
  date="2003-01-10T09:36:18"
  subject="Re: [Caml-list] record declaration, SML">
</msg>
</msg>
<msg 
  url="2003/01/1ca66d24a440edbd8e33b050a8ffc794"
  from="Daniel de Rauglaudre &lt;daniel.de_rauglaudre@i...&gt;"
  author="Daniel de Rauglaudre"
  date="2003-01-09T22:42:08"
  subject="Re: [Caml-list] record declaration, SML">
<msg 
  url="2003/01/d88536eb5cd8c413b396f1cff8f000e6"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2003-01-09T23:11:48"
  subject="Re: [Caml-list] record declaration, SML">
<msg 
  url="2003/01/5139d8a47eedbc92eee9fe549d84283c"
  from="Daniel de Rauglaudre &lt;daniel.de_rauglaudre@i...&gt;"
  author="Daniel de Rauglaudre"
  date="2003-01-10T02:59:41"
  subject="Re: [Caml-list] record declaration, SML">
</msg>
<msg 
  url="2003/01/be4cf6635106b2ef386963204ac08a99"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-01-10T03:45:45"
  subject="Re: [Caml-list] record declaration, SML">
<msg 
  url="2003/01/e1fc2cb6dafc061afc5f6f4faf822561"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2003-01-10T07:43:33"
  subject="Re: [Caml-list] record declaration, SML">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Fri, 10 Jan 2003, Alessandro Baretta wrote:
&gt; Daniel de Rauglaudre wrote:
&gt; &gt; Hi,
&gt; &gt; 
&gt; &gt; 
&gt; &gt;&gt;What's best translation of the following SML type?
&gt; &gt;&gt;datatype t = C of { f : int }
&gt; &gt; 
&gt; &gt; 
&gt; &gt; A solution is:
&gt; &gt;   type t = C of &lt; f : int &gt;
&gt; 
&gt; Interesting solution. However, Ocaml does not support 
&gt; defining objects on the fly. The following
&gt;  &gt; let c = new object method f = 1 end in C c
&gt; is not valid Ocaml.
&gt; 
&gt; So, in order to define just one value one needs to define an 
&gt; entire class as in the following example.
&gt; 
&gt; class f_one = object method f = 1 end
&gt; let res = C (new f_one)

Is this such a big problem? I imagine we're more likely to provide a 
smart constructor for t, something like 

    let mkC o = C(o :&gt; &lt; f : int &gt;)

and just stuff any object with method f : int in there. If we only want there 
to be one kind of thing, we're better off using a record. Of course, Daniel 
doesn't have that option since he is discussing a syntactic transformation 
from SML records into OCaml constructs, and hence using the class system makes 
sense on account of the differences between SML record typing and that of 
OCaml. 

&gt; BTW, why is something like the above not in the language? It 
&gt; seems only natural to have such a feature since an analogous 
&gt; construct exists for structs.

There are no anonymous records (like SML has) either, so if you see classes as 
analogous to records rather than structs it doesn't seem so unnatural. No, I 
realize that's not a real explanation. 

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

