Skip to content

Latest commit

 

History

History

wip-compile-uncurry

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Uncurrying lambda expressions

This is an attempt to compile a language where all functions take a single argument to a language where functions take multiple arguments. The intention is to explore ways of supporting uncurrying for DSLs that compile to high-level languages with multiparameter functions.

I didn’t really follow any technical resources when implementing this, just attempted to implement things myself beginning with what I saw in Christoph Breitkopf’s implementation, extending it to handle applications on variables.

Resources

As far as I can tell, uncurrying is often done as a part of other transformations, like closure conversion, and so it can be hard to find specific resources and examples that explain this specific transformation in isolation, or in much depth.

ReScript apparently has very good support for high level uncurrying, targeting high-level Javascript, (seen formerly in Bucklescript). Unfortunately I’ve not been able to figure out where this is actually implemented and figure out how it works.

As mentioned previously, Christoph Breitkopf implemented a simple form of uncurrying that does not handle partial applications as part of a contest entry for ICFP 2014.

Lower level approaches to uncurrying can be found in Johan Nordlander’s slides for their 2011 course, Compiling Functional Languages. Lecture 2 (from page 17) is relevant, although I hear that it might be preferrable to avoid the lambda lifting that it employs. Lecture 6 shows an interesting approach that uses types to keep track of function arities.

Making a fast curry: push/enter vs. eval/apply for higher-order languages is a famous paper that explores how to efficiently handle the troublesome cases of partial application where the arity of arguments are unknown, but doesn’t go through how to implement the easy cases, as far as I can tell! See also Xavier Leroy’s commentary on this work in these slides.

Update as of 2024-08-20

I’ve found some more resources on arity analysis: