On 13 February 2015 at 20:21, Jonathan S. Shapiro <[email protected]> > > From the standpoint of cleanliness, I agree with you. The problem is that > solving this only at module level isn't good enough. The programmer MUST be > able to look at the line of code in front of them and understand which > things do not allocate. Not allocating 99% of the time just isn't good > enough. >
If you care about heap allocation (say in an interrupt handler) simply do not use the curried form of a function: import 'C' add(int32, int32) -> int32 Ie use it in its native arity. The import still needs to specify the type to facilitate separate compilation where the definition of add is in a different module. > > Given your proposal, consider a function using curried application that > has been constrained by a NOALLOC effect. Does an algorithm exists that is > guaranteed to perform curried application without any allocation, in the > case where the function being applied cannot be statically resolved, and so > we cannot guess the function's native arity given that you propose it > should not be encoded in the type? > The compiler would pass the import and store two type signatures for the function, the native-type and the 'local-type'. The program would initially be type checked with the local-type, then optimisation passes applied, then type checked again with the native-type, and fail this type check if it has been unable to solve the uncurrying (or it can add thunks if allowed). I cannot prove it is possible, but I have a hunch that by AST manipulation you can always solve the uncurrying problem. The idea is that the function must be applied to both arguments at some point, so we just need to bring the arguments together (this assumes purity) by reordering the code. I think beta reduction would work. imagine: inc x = add 1 x f x = inc x We can uncurry this by substituting "add 1 x" for "inc x". You still need to decide on what happens with side-effects, I would again want monadic effect control so all 'application' arrows are pure, but you could assume all side effects occur in the last arrow of a curried function type, and therefore you only have to preserve the order of the final applications in the AST. Keean.
_______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
