uncurrying
Stephen Weeks
sweeks@wasabi.epr.com
Sat, 18 Sep 1999 16:53:11 -0700 (PDT)
> A question about the SXML representation of a curried app: if f = \x.\y. x + y,
> and there is a curried application of the form: f 3 4, then the corresponding
> SXML code for the app would be something like:
>
> let y1 = 3
> y2 = f y1
> y3 = 4
> y4 = y2 y3
> ...
>
> In this case, I'm not quite sure how to easily and generally identify an
> uncurry-able function since there may be an arbitrary collection of bindings
> between curried calls.
>
> Any suggestions?
As in xml/call-count.fun, I would store something associated with each
variable telling if that variable is the result of a (curried)
application of a lexically apparent function. This can be easily
computed top-down. So, in the above example, you would notice that f
is a known lambda, then notice that y2 is an application of f, then
notice that y4 is an application of y2, and hence an application f.
The arguments are really unimportant.
As to the transformation, since you will only do this for curried
functions, you don't need to worry about side effects and can always
replace the deepest application (y4 in the above example) with the
uncurried version and delete the intermediate applications. So, if
you know that y4 = (f y1) y3, then replace that with y4 = f(y1, y3)
and then notice that the binding of y2 can be deleted. This can be
done in a bottom up way given the information from the first pass.
Another example of a similar style of code is xml/polyvariance.fun.