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
[Caml-list] Unix.kill on Win32
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] static class member....
> > Yes, it says in the language introduction (the part on objects)
> >
> > Let-bindings within class definitions are evaluated before the object
> > is constructed
> Well I take it back. And I must admit that I always have used
> let-bindings as if they are local to the instance.
> The question though is why does my example work? Is this a bug
> in the compiler?

It's not a bug.
You can see your class as function to get a better idea of what's happenning

let foo =
    let x = ref 0 in
    (fun () -> !x)

against :

let foo () =
    let x = ref 0 in

To answer to the original post about class static, there is no concept of
static class variables in Ocaml , but you can still write accessors to a
variable declared outside the class scope :

let counter = ref 0

class foo =
        method incr = incr counter
        method print = Printf.printf "counter = %d\n" !counter

Nicolas Cannasse

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: