Browse thread
[Caml-list] Unix.kill on Win32
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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
!x
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 =
object
method incr = incr counter
method print = Printf.printf "counter = %d\n" !counter
end
Nicolas Cannasse
-------------------
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