Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-08-24 (09:57)
From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@e...>
Subject: [Caml-list] Side effect in non-commutative context

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 =
           Some (g ())
         with Fail -> None
         match result with
           | None -> solve tail
           | Some r -> r :: solve tail

with the direct construction

  | g :: tail ->
       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 Archives:
Bug reports: FAQ:
Beginner's list: