<?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/e1fc2cb6dafc061afc5f6f4faf822561"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2003-01-10T07:43:33"
  subject="Re: [Caml-list] record declaration, SML"
  prev="2003/01/497f17c92c4637eb2e9cf2e37052fe5a"
  next="2003/01/78b896e07d18240e06adb3dd5c3c7870"
  prev-in-thread="2003/01/be4cf6635106b2ef386963204ac08a99"
  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>


brogoff@speakeasy.net wrote:
&gt; On Fri, 10 Jan 2003, Alessandro Baretta wrote:
&gt;&gt;So, in order to define just one value one needs to define an 
&gt;&gt;entire class as in the following example.
&gt;&gt;
&gt;&gt;class f_one = object method f = 1 end
&gt;&gt;let res = C (new f_one)
&gt; 
&gt; 
&gt; Is this such a big problem? I imagine we're more likely to provide a 
&gt; smart constructor for t, something like 
&gt; 
&gt;     let mkC o = C(o :&gt; &lt; f : int &gt;)

No, it's not a bit problem. I was just wondering

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

Besides, Daniel showed us that you can actually define a 
record on the fly without cluttering the class namespace.

   let module M =
     struct
       class a = object val f = 1 method f = f end
      end
   in
   C (new M.a)

This raises one more question:
let module P =
	struct type t = { f : int } let x = { f = 1 } end
in P.x;;

The above is not valid Ocaml because P.x has a type which 
escapes its scope. This is quite evident. Now I would expect 
Daniel's code to be rejected by the same standards, but it 
is not. Why? Does class a not escape its scope?

&gt; 
&gt;&gt;BTW, why is something like the above not in the language? It 
&gt;&gt;seems only natural to have such a feature since an analogous 
&gt;&gt;construct exists for structs.
&gt; 
&gt; 
&gt; There are no anonymous records (like SML has) either, so if you see classes as 
&gt; analogous to records rather than structs it doesn't seem so unnatural. No, I 
&gt; realize that's not a real explanation. 

Right. Even unnamed records are missing. But it's different 
because the Ocaml type system does not support record 
subtyping--even if record type b in module B defines all 
fields of record type a in module A with the same types, B 
is not a subtype of A. On the other hand, object subtyping 
exists already in the language, so on-the-fly definitions of 
objects à la façon de Daniel are more meaningful and useful.

Alex

-------------------
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>

