
Hi, Could you explain when the compiler inserts _apply1 and _apply2. As _apply2 f a b = _apply1 (_apply1 f a) b, how is _apply2 useful? Thanks, Saswat

Saswat Anand
Could you explain when the compiler inserts _apply1 and _apply2.
These are inserted during lambda-lifting, to ensure the correct laziness of certain applications.
As _apply2 f a b = _apply1 (_apply1 f a) b, how is _apply2 useful?
Evaluating _apply2 f a b is slightly more efficient at runtime than evaluating the nested application _apply1 (_apply1 f a) b Time profiling shows that, for many programs, _apply1 and _apply2 take a significant percentage of the total runtime, so it is wise to avoid extra runtime costs wherever possible, since their only purpose is to introduce a lazy suspension for semantic correctness. Regards, Malcolm

so it is wise to avoid extra runtime costs wherever possible, since their only purpose is to introduce a lazy suspension for semantic correctness.
For example if I have, fun p var (Tree t cs) = let ... g = fun new_ass (var+1) in ... which the compiler translates to, g = _apply2 fun new_ass (var+1) how can I avoid _apply2 ? I tried g = (fun $! new_ass) $! (var+1), but with this I get cells of Prelude.$! in place of Prelude._apply2. Thanks, Saswat
participants (2)
-
Malcolm Wallace
-
Saswat Anand