You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"
The text was updated successfully, but these errors were encountered:
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.
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.
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
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"
The text was updated successfully, but these errors were encountered: