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

Syntax for partially applied functions #147

Closed
valis opened this issue Feb 24, 2020 · 9 comments
Closed

Syntax for partially applied functions #147

valis opened this issue Feb 24, 2020 · 9 comments
Labels
Milestone

Comments

@valis
Copy link
Collaborator

@valis valis commented Feb 24, 2020

Implement a notation for partially functions such as f(a,-,c). I suggest __ because - and _ are already taken.

The lambda should be inserted only in specific positions such as the argument of an application (but not in infix operator).

f a __ c == (\lam x => f a x c)
(\lam c => f __ c) == (\lam c x => f x c)
pmap __.1 s == pmap (\lam t => t.1) s
__ a == (\lam f => f a)
x + __.2 == (\lam t => x + t.2)
field {__} + y == (\lam s => field {s} + y)
a * __ + b * c == (\lam x => a * x + b * c)
f __ + 3 == (\lam x => f x + 3)
(__.1, __.2) == (\lam t => t.1, \lam t => t.2)
(\case f __ \with { }) == (\lam x => \case f x \with { })

If __ occurs more than once in an expression, this can be interpreted either as a lambda with two parameters or as a lambda with one parameter which is used twice. For example, __ * a + __ * b could be interpreted as either \lam x y => x * a + y * b or \lam x => x * a + x * b. The first interpretation looks more natural to me.

@valis valis added the feature label Feb 24, 2020
@ice1000
Copy link
Contributor

@ice1000 ice1000 commented Mar 27, 2020

__ * a + __ * b may also be (\lam x => x * a) + (\lam x => x * b), no?

@ice1000
Copy link
Contributor

@ice1000 ice1000 commented Mar 27, 2020

If it shall desugar app exprs recursively, how about parentheses? Say, f (a __ b), should it become \lam x => f (a x b) or f (\lam x => a x b)?

@valis
Copy link
Collaborator Author

@valis valis commented Mar 27, 2020

__ * a + __ * b may also be (\lam x => x * a) + (\lam x => x * b), no?

It could be, but it shouldn't be.

@valis
Copy link
Collaborator Author

@valis valis commented Mar 27, 2020

If it shall desugar app exprs recursively, how about parentheses? Say, f (a __ b), should it become \lam x => f (a x b) or f (\lam x => a x b)?

Parenthesis is not part of the AST. In you example, it's an argument of an application. The original messages mentions this:

The lambda should be inserted only in specific positions such as the argument of an application (but not in infix operator).

@ice1000
Copy link
Contributor

@ice1000 ice1000 commented Mar 27, 2020

So, IIUC, a * (__ + b) should be \lam x => a * (x + b), right?

@ice1000 ice1000 closed this as completed Mar 27, 2020
@ice1000 ice1000 reopened this Mar 27, 2020
@valis
Copy link
Collaborator Author

@valis valis commented Mar 27, 2020

Basically, it should be inserted immediately except for a few special cases. I list a few of them in my original message (there might be more though). So, if it does not make sense to insert lambda in some place, it should be inserted higher. For example, this happens in \case expressions. It also happens in \Pi and \Sigma types, which I did not mention.

Binops is a special case. It certainly possible to have a lambda under binop, but it rarely happens in practice and it is more natural to desugar __ * a + b into \lam x => x * a + b than (\lam x => x * a) + b.

@valis
Copy link
Collaborator Author

@valis valis commented Mar 27, 2020

So, IIUC, a * (__ + b) should be \lam x => a * (x + b), right?

Yes

@ice1000
Copy link
Contributor

@ice1000 ice1000 commented Mar 28, 2020

1 + \case __ \with {} is translated to \lam i => i + \case i \with {}

ice1000 added a commit that referenced this issue Apr 3, 2020
ice1000 added a commit that referenced this issue Apr 3, 2020
@ice1000 ice1000 added this to the 1.4 milestone Apr 3, 2020
ice1000 added a commit that referenced this issue Apr 3, 2020
ice1000 added a commit that referenced this issue Apr 3, 2020
ice1000 added a commit that referenced this issue Apr 3, 2020
ice1000 added a commit that referenced this issue Apr 3, 2020
ice1000 added a commit that referenced this issue Apr 5, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 6, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
ice1000 added a commit that referenced this issue Apr 13, 2020
@ice1000
Copy link
Contributor

@ice1000 ice1000 commented Apr 17, 2020

Shall be fixed by #199?

@valis valis closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants