caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [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

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).