Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fe: support for partial application #2265

Merged
merged 30 commits into from
Dec 4, 2023
Merged

Conversation

fridis
Copy link
Member

@fridis fridis commented Nov 23, 2023

Support for partial application of function calls.

This is an implementation of most of the missing syntax sugar for partial application that was suggested in the last table of Fuzion Design • Syntax Sugar for Lambdas.

In particular, when a call is assigned to field (via argument passing to a call or via an assignment using :=) and the target type is available, then partial application will be used if necessary. Then, the following transformations may occur:

partial expression expanded to explanation
f x y a,b,c -> f x y a b c partial call turned into a lambda
f x y () -> f x y a call may be turned into a nullary function
++ x a -> a ++ x A prefix or postfix operator may be turned into an infix operator
x ++ a -> x ++ a dto.
- a -> -a or a -> a- or a,b -> a-b A single operator may become a prefix, postfix, or infix operator in a lambda
.as_string a -> a.as_string A dot followed by a call is a call in a lambda that receives its target as an argument
-1 a -> x - 1 a numeric literal with a sign may become an infix operator

Note that a single operator given as an argument to a call will be parsed as a postfix or infix operator, so it usually will have to be enclosed in parentheses as in

     (-)

Additionally, this patch does some changes that are not directly related to partial application:

  • numeric literals no longer may have detached signs, i.e., - 1 is no longer a numeric literal whose type will be inferred from what it is assigned to, but prefix - applied to the i32 constant 1.
  • checks for types within choices now have a helper method findInChoice in AbstractType
  • fix Postfix operand in parentheses with leading white space results in syntax error #2272, postfix operator with leading whitespace in parentheses causes error
  • for simple tests, make record now uses the jvm backend, while make record_int records output using the integer backend.

`resolveSyntacticSugar`.

The reason is that `checkTypes` should just perform checks and not change the
state.
Now, `- 128` is no longer the same as `-128` (the former is an `prefix -`
applied to a constant `i32` while the latter is a `NumLiteral` hat can be
assigned to `i8`.

Added constructor test cases to negative tests, removed failing tests from
positive tests.
Remove old, unused code. Also, remove the ability to equip a lambda expression
with a contract.
@fridis fridis marked this pull request as ready for review December 1, 2023 07:37
@michaellilltokiwa michaellilltokiwa merged commit 0ed5f77 into main Dec 4, 2023
5 checks passed
@michaellilltokiwa michaellilltokiwa deleted the partial_application branch December 4, 2023 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postfix operand in parentheses with leading white space results in syntax error
2 participants