Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004807OCamlOCaml documentationpublic2009-05-26 16:432012-03-24 15:01
Reporterlavi 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.11.0 
Target VersionFixed in Version3.12.0+dev 
Summary0004807: class initialization order
Descriptiond'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"

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0005564)
lavi (reporter)
2010-06-17 16:41

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.
(0005565)
garrigue (manager)
2010-06-18 02:22

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.
(0005567)
garrigue (manager)
2010-06-18 04:59

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

- Issue History
Date Modified Username Field Change
2009-05-26 16:43 lavi New Issue
2010-06-17 16:41 lavi Note Added: 0005564
2010-06-18 02:22 garrigue Note Added: 0005565
2010-06-18 04:59 garrigue Note Added: 0005567
2010-06-18 04:59 garrigue Status new => resolved
2010-06-18 04:59 garrigue Fixed in Version => 3.12.0+dev
2010-06-18 04:59 garrigue Resolution open => fixed
2010-06-18 04:59 garrigue Assigned To => garrigue
2012-03-24 15:01 xleroy Status resolved => closed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker