Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Class variables in O'Caml???
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1996-05-10 (11:00)
From: Thorsten Ohl <ohl@c...>
Subject: Class variables in O'Caml???

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