Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Side effect in non-commutative context
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@e...>
Subject: [Caml-list] Side effect in non-commutative context
    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