I did some tests and it seems that with flamba the equivalence between the two idioms is restored. I tested with this functions:
let f x =
ignore (Array.create ~len:50 x);
fun y -> x + y
let f_staged x =
ignore (Array.create ~len:50 x);
Staged.stage (fun y -> x + y)
let g x y = x + y
let h x y = x * y
I composed or piped f
or g
with h
and got this results:
Name Time/Run mWd/Run Percentage
-------------------- ---------- --------- ------------
f composed 3.20ns 3.51%
f with pipe 91.09ns 51.00w 100.00%
g composed 3.19ns 3.50%
g with pipe 3.17ns 3.48%
compose with stage 3.19ns 3.50%
pipe with stage 3.18ns 3.49%
The pipe idiom works well only with functions of the form fun x y -> ...
but if we do some heavy computation with x
before defining fun y -> ...
then we have to stage the result or use the composition idiom.