caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@yquem.inria.fr
Subject: Execution order in class construction
Date: Fri, 03 Apr 2009 23:09:21 +0200	[thread overview]
Message-ID: <87vdpligvy.fsf@frosties.localdomain> (raw)

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


             reply	other threads:[~2009-04-03 21:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03 21:09 Goswin von Brederlow [this message]
2009-04-06  4:41 ` [Caml-list] " Jacques Garrigue
2009-04-06  6:12   ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vdpligvy.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).