Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Call-Site Code Replacement

16 views
Skip to first unread message

Jan Burse

unread,
Oct 22, 2012, 1:54:33 PM10/22/12
to
Dear All,

I just wonder whether it is possible in a functional
language to do call site replacement. I envision this
as a special form of lazyness.

Basically I would call somewhere a function f
with an argument a:

... (f a) ...

The function would then manage to replace itself
by a function g with an argument b:

... (g b) ...

So that the next time the original call site of (f a)
is invoked in fact (g b) is invoked.

Hints welcome.

Bye

Dirk Thierbach

unread,
Oct 22, 2012, 3:29:02 PM10/22/12
to
This replacement is clearly not sound, unless somehow you can guarantee
that (f a) and (g b) will always have the same result.

So a pure functional language with referential transperancy will never
be able to do that, and for good reasons.

However, one can replace the call (f a) with the *result* of this
call, so the next time it is invoked it won't have to do the
computation again. That is actually done in Haskell, for example, by
the compiler without any need for programmer intervention.

- Dirk



0 new messages