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

RFC: Generalised dot syntax for postfix application #342

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ziman
Copy link
Collaborator

@ziman ziman commented Apr 30, 2020

Here's a more radical idea: .(expr) and .name are postfix applications of expr/name that bind tighter than application.

Some examples:

  • printLn user.name.length
  • "hello".length.(+3).printLn
  • map (.length.show) ["foo", "booo"]
  • mySet.(insert "hello").(insert "world") <+> otherSet
  • 5 .div 3
  • 5 .(div {ty=Int}) 3
  • foo .(NS.(>>=) {lin = True}) bar

This patch did not require any changes to the existing code in the stdlib and tests (other than the recent record test).

One issue I see with this is that idiomatic functions put the main arguments last so you can't write myList.map (+1) and you have to write myList.(map (+1)) instead. There is myList.for printLn but that works only in Applicative contexts.

@ziman ziman changed the title RFC: Generalised dot application RFC: Generalised dot syntax for postfix application Apr 30, 2020
@gallais
Copy link
Collaborator

gallais commented May 1, 2020

I have a love/hate relationship with this proposal. But mostly love.

@ziman
Copy link
Collaborator Author

ziman commented May 3, 2020

If we do this, we should tell the elaborator not to generalise names after dots to avoid foo.n -> T being translated as {0 n : _} -> n foo -> T.

@gallais
Copy link
Collaborator

gallais commented May 3, 2020

I expect foo is the one that would be implicitly bound as it is the one
in argument position.

@edwinb
Copy link
Owner

edwinb commented May 9, 2020

I'm a bit scared of this one, although I do kind of like it... I think... maybe if we are going to have it, it should be hidden behind a %language pragma?

I think we've overdone syntactic trickery and experimentation in the past, but somehow I still want to play with this...

@andylokandy
Copy link
Contributor

I'll feel a bit awkward if they're identical:

  • "hello".(printLn . (+3) . length)
  • "hello".length.(printLn . (+3))
  • "hello".length.(+3).printLn

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.

4 participants