caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Execution order in class construction
@ 2009-04-03 21:09 Goswin von Brederlow
  2009-04-06  4:41 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Goswin von Brederlow @ 2009-04-03 21:09 UTC (permalink / raw)
  To: caml-list

Hi,

I'm wondering if the execution order is defined during class
construction. For example:

let n = ref 0
let next () = incr n; !n
class foo = object
  val x = next ()
  val y = next ()
  val z = next ()
  method print = Printf.printf "%d %d %d\n" x y z
end

Will that always give x < y < z or could it initialize the values in
different order?

In my use case I want to parse the values from a stream and have
inheritance between classes.

class foo stream = object
  inherit base1 stream
  inherit base2 stream
  val x = parse_x stream
  val y = parse_y stream
end

Will that always execute in order? If the order is undefined then that would
make things more complex and require additional type definitions:

class foo stream =
  let base1_temp = parse_base1 stream in
  let base2_temp = parse_base2 stream in
  let x_temp = parse_x stream in
  let y_temp = parse_y stream
  in
    object
      inherit base1 base1_temp
      inherit base2 base2_temp
      val x = x_temp
      val y = y_temp
    end

MfG
        Goswin


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

end of thread, other threads:[~2009-04-06  6:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-03 21:09 Execution order in class construction Goswin von Brederlow
2009-04-06  4:41 ` [Caml-list] " Jacques Garrigue
2009-04-06  6:12   ` Goswin von Brederlow

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