Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] class variables?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <frisch@c...>
Subject: Re: [Caml-list] class variables?
On Fri, 11 Jan 2002, Maxence Guesdon wrote:

> *But* if class foo has parameters, then the expressions before the 'objet' keyword are evaluated at
> each creation of a new instanciation, so in the following code
>
> class foo () =
>   let my_list = [ "foo" ; "bar"] in
>   object
>     ...
>   end
>
> let t = new foo
> let u = new foo
>
> t and u are two objects which don't share the list my_list.

You can write:

class foo =
  let my_list = [ "foo" ; "bar"] in
  fun () -> object
    ...
  end

in order to share my_list ...  or simply use a value defined
outside the scope of the class definition.


Alain

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr