Do you mean something like this?

let g = function 0 -> raise G | n -> n
let f = function 1 -> raise F | n -> n

map f (map g [1;0]) ===> raise G
map (f %> g) [1;0]  ===> raise F

It is true, the exception prevents any optimization that would reorder
two functions that both throw an excepition.

Precisely
 
But many other
optimizations are still possible, e.g. common subexpression
elimination:

let n =
  let x = f (g 1) in
  let y = g 1 in
  x + y

==>

let n =
  let t = g 1 in
  let x = f t in
  let y = t in
  x + y

To some degree:

let n =
  let x = f (g 1) (h ()) in
  let y = g 1 in
  x+y

is a different program than

let n =
  let t = g 1 in
  let x = f t (h ()) in
  let y = t in
  x+y

As it reorders (g 1) and (h ()). I think the rule is something like: when the program is in monadic form, and you have a call to e, you can factor in every subsequent calls to e. Which I guess is good enough. But I would tend to believe deforestation would be tremendously more useful than common expression elimination.
 

MfG
        Goswin

--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs