<?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/11/0e841f152ab8a939e37e43f48a0d5095"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2003-11-20T15:53:35"
  subject="Re: [Caml-list] classes, objects, and class variables"
  prev="2003/11/41b7013f566a30eb640361b86fe8d780"
  next="2003/11/81eb4f0d376b6f9e176101051e0c06b2"
  prev-in-thread="2003/12/78f379d2c9642d4987dc5690a39dbaa7"
  prev-thread="2003/11/94d3362b05f025d593538a0c9478ebd5"
  next-thread="2003/11/81eb4f0d376b6f9e176101051e0c06b2"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] classes, objects, and class variables">
<msg 
  url="2003/11/94ca042f44be533f27f5a8b42b4b788f"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-11-20T13:07:20"
  subject="[Caml-list] classes, objects, and class variables">
<msg 
  url="2003/12/78f379d2c9642d4987dc5690a39dbaa7"
  from="james woodyatt &lt;jhw@w...&gt;"
  author="james woodyatt"
  date="2003-12-23T07:38:12"
  subject="Re: [Caml-list] classes, objects, and class variables">
</msg>
<msg 
  url="2003/11/0e841f152ab8a939e37e43f48a0d5095"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2003-11-20T15:53:35"
  subject="Re: [Caml-list] classes, objects, and class variables">
</msg>
</msg>
</thread>

<contents>
Am Don, 2003-11-20 um 14.07 schrieb Jacques Garrigue:
&gt; To whom it may concern,
&gt; 
&gt; I'm in the process of improving the ocaml class system.
&gt; Principally the following two points:
&gt; 1) making class creation cheaper.
&gt;    If you believed you could create classes in a "let module", and
&gt;    get away with it, you weere: it was prohibitively expensive in both
&gt;    time and space. Now I'm seeing 10000% speeups.
&gt; 2) using this to make objects (or final classes) first class.
&gt;    Be able to write "let o = object (self) method m = ... end"
&gt;    Side advantage, there are no restrictions on polymorphism.
&gt; 
&gt; But in this process, I came along with the rather strange behaviour of
&gt; class variables. Class variables are defined by a let before any
&gt; parameters, for instance
&gt;   class c = let a = init () in fun ... -&gt; object ... end
&gt; Their current semantics is to be evaluated repeatedly, once for c,
&gt; but again for all classes inheriting from c. The problem is that this
&gt; is costly for the implementation, doesn't fit well with the
&gt; possibility to create dynamically an arbitrary number of classes
&gt; inheriting from, and that I don't see what it's intended for.
&gt; 
&gt; So I'm planning to revert to the more intuitive semantics: evaluation
&gt; when creating c, but never again.
&gt; 
&gt; Does that bother anybody?

Just experimenting (to understand what you mean, I never discovered this
"feature" myself):

- Classes without arguments:

# class x = let _ = prerr_endline "X" in object end;;
X
class x : object  end
# class y = let _ = prerr_endline "Y" in object inherit x end;;
X
Y
class y : object  end

-  Classes with arguments:

# class x() = let _ = prerr_endline "X" in object end;;
class x : unit -&gt; object  end
# class y() = let _ = prerr_endline "Y" in object inherit x() end;;
class y : unit -&gt; object  end
# new x();;
X
- : x = &lt;obj&gt;
# new y();;
Y
X
- : y = &lt;obj&gt;

I suppose you are only referring to the case where classes do not have
arguments (because in the other case, the class variables can be
dependent on class arguments, so they must be evaluated again for every
subclass).

I'm quite surprised that the class variables are evaluated in the
reverse order in the argument-less case. This seems to be an
inconsistency anyway, so I guess this is a rarely used feature. (When
"inherit" is read as an _instruction_ to initialize the named class
again for usage in the subclass, the order of evaluation should be the
same as in the case with arguments.)

If somebody needs repeated evaluation, he can add unit arguments to the
class definition.

So my conclusion is: do it.

Gerd 
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------

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

