caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Class variables in O'Caml???
@ 1996-05-10 10:46 Thorsten Ohl
  1996-05-10 12:57 ` Class variables in O'Caml??? + questions Christian Boos
  0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Ohl @ 1996-05-10 10:46 UTC (permalink / raw)
  To: caml-list


I have played a little bit with O'Caml yesterday and found that the
new features very conveniently formalize what I had been doing with
mutable records already.  Good job!

I have one question however: it seems that all variables in a class
are instance variables.  Have I overlooked something in the
documentation or can somebody explain to me why class variables
(i.e. variables that are shared mong all instances of a class) are a
bad idea?

The typical application is a class of non-uniform random number
generators, where the distribution to be generated would be an
instance variable, while the state of the underlying uniform
generator should be a class variable.  This way, differrent instances
will generate different distributions, but draw from the _same_ source
of random numbers.

It is possible to emulate this with references, of course.  But it
would be somewhat unnatural ...

Cheers,
-Thorsten





^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Class variables in O'Caml??? + questions
@ 1996-05-13 19:04 David Gurr
  0 siblings, 0 replies; 6+ messages in thread
From: David Gurr @ 1996-05-13 19:04 UTC (permalink / raw)
  To: caml-list



Jerome Vouillon <vouillon@clipper.ens.fr>:

> On Fri, 10 May 1996, Thorsten Ohl wrote:
> > Sure, it us possible to do it.  But, IMHO, class variables should be
> > declared in the class and be opaque.  
> > ...
> > I'm just curious if (and why) this syntactic sugar has been left out
> > intentionally.
> 
> It has not been left out intentionally. Many object-oriented languages 
> (C++, Objective C and Modula 3, for instance) do not have class variables, 

C++ does have class variables but since everything is renamed in C++
they are called static member variables or static data members or ... .

> ... they can be easily simulated using references as you noticed.

Why not make class variables exactly that,  slots of the class object?

-D





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1996-05-14  8:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-10 10:46 Class variables in O'Caml??? Thorsten Ohl
1996-05-10 12:57 ` Class variables in O'Caml??? + questions Christian Boos
1996-05-10 15:13   ` Thorsten Ohl
1996-05-13 16:36     ` Jerome Vouillon
1996-05-13  1:06   ` Upcoming O'Labl Jacques GARRIGUE
1996-05-13 19:04 Class variables in O'Caml??? + questions David Gurr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).