* [Caml-list] Side effect in non-commutative context
@ 2004-08-24 9:54 Diego Olivier Fernandez Pons
2004-08-26 9:01 ` Diego Olivier Fernandez Pons
0 siblings, 1 reply; 2+ messages in thread
From: Diego Olivier Fernandez Pons @ 2004-08-24 9:54 UTC (permalink / raw)
To: caml-list
Bonjour,
I intoduced some time ago a bug when rewritting a code because of an
uncontrolled side effect in a non-commutative context :
I replaced
match continuations with
| [] -> []
| g :: tail ->
let result =
try
Some (g ())
with Fail -> None
in
match result with
| None -> solve tail
| Some r -> r :: solve tail
with the direct construction
| g :: tail ->
try
g () :: solve tail
with Fail -> solve tail
Since Caml evaluates from right to left, the exception that was being
catched was the one raised by [solve tail] and the correct result
computed by [g ()] was thrown. This bug would have been quite hard
to find if I hadn't had a working code to compare with (and even
like this it took me some time).
The right to left evaluation order if implemetation dependent and this
bug could have been there for a long time if Caml did happen to
evaluate in a left-to-right way.
Would it be possible to add to the caml compiler some detection and
reporting of side-effects in non-commutative (implementation
dependent) context ?
Diego Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Side effect in non-commutative context
2004-08-24 9:54 [Caml-list] Side effect in non-commutative context Diego Olivier Fernandez Pons
@ 2004-08-26 9:01 ` Diego Olivier Fernandez Pons
0 siblings, 0 replies; 2+ messages in thread
From: Diego Olivier Fernandez Pons @ 2004-08-26 9:01 UTC (permalink / raw)
To: caml-list
Bonjour,
I have been said privately that detecting side-effects may be quite
difficult.
Quid about the work done by François Pessaux and Xavier Leroy on
type-based analysis of uncaught exceptions (1998) ? Is it planned to
be added to the Caml compiler (I am of course directly interested
because heavy user of exceptions but I don't know how important this
is for typical Caml programs like symbolic computation, etc.)
An other point is that I meant of course compilation-time warnings.
let rec map f = function
| [] -> []
| head :: tail -> f head :: map f tail
Once a function like [map] is compiled there is no way to know if it
intented to be used in a commutative context or not. What I had in
mind was just propagating a "with-side-effects" tag in the inferred
type (that is more or less the way exceptions are handled in Pessaux
and Leroy's work, isn't it ?)
Diego Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-08-26 9:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 9:54 [Caml-list] Side effect in non-commutative context Diego Olivier Fernandez Pons
2004-08-26 9:01 ` Diego Olivier Fernandez Pons
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).