Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class initialization order #4807

Closed
vicuna opened this issue May 26, 2009 · 3 comments
Closed

class initialization order #4807

vicuna opened this issue May 26, 2009 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented May 26, 2009

Original bug ID: 4807
Reporter: lavi
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2012-03-24T14:01:46Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.0
Fixed in version: 3.12.0+dev
Category: documentation
Monitored by: @ygrek

Bug description

d'après le paragraphe 6.9.2 de la doc,
"fun x -> class ..." est une fonction des valeurs vers les classes,
et l'application est comme l'application d'expression...
Dans l'exemple suivant, on s'attendrait donc à ce que les classes a et c produisent le même résultat. L'application devrait donc être plus détaillée.

class a = let () = print_endline "hello"
in object end

class b s =
let () = print_endline s
in object end

class c = b "hello"

@vicuna
Copy link
Author

vicuna commented Jun 17, 2010

Comment author: lavi

I have no news about this.

Is it really a feature that side effect in class are done immediatly, but delayed at object creation when under an applied function ?
If so it should be docummented.

@vicuna
Copy link
Author

vicuna commented Jun 18, 2010

Comment author: @garrigue

I missed (or forgot?) your first report.
I agree that the discrepancy is disturbing.
However, fixing it would require changing the internal representation of classes.
Namely, currently an object constructor is a function taking first the object we are constructing, and then its other arguments. So we cannot partially apply it at class creation. In order to do that, it would need to take the object we are filling as last argument.

Before 2003, side-effects in constructors were evaluated once per class, which complicated the compilation of classes defined by applications. But this doesn't seem to change the behaviour in your examples.

@vicuna
Copy link
Author

vicuna commented Jun 18, 2010

Comment author: @garrigue

I corrected the reference manual to specify the evaluation time.
Correcting the implementation to allow side-effects at class creation time seemed too complex, and not very useful.
Note that early evaluation occurs only when the let is at the very beginning of the class. For instance, in the following example, evaluation occurs only when an object is created:

class c = object inherit (let () = print_endline "Hello" in object end) end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants