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

Add support for Partial Application #37973

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

Pokute
Copy link

@Pokute Pokute commented Apr 15, 2020

PR adding partial application support to TypeScript. The proposal is currently a stage 1 proposal for EcmaScript. It "introduces a new syntax using the ? token in an argument list which allows you to partially apply an argument list to a call expression by acting as a placeholder for an argument."

const square = Math.pow(?, 2);
console.log(square(4)); // 16

This feature by itself seems pretty minor by itself, but in my opinion, it's a crucial part of pipeline operator proposal (F# variant).

New at 2021-10-04:

  • Now supports f~(?, 1) -form (Syntactic marker for partial application) of partial application.
  • Old f(?, 1) -form still works but after this version, the support will be removed.
  • Is a lot more complete and has a bit more tests.
  • Should support most of the features of the Syntactic marker proposal variant, but...
  • Doesn't yet support the ... -rest argument.

Testing

Playground Link

To test it in your project, add following to your package.json:

{
    "devDependencies": {
        "typescript": "npm:@typescript-deploys/pr-build@4.5.0-pr-37973-15"
    }
}

and then run npm install.

PR state

  • There is an associated issue in the Backlog milestone (required)
  • Code is up-to-date with the master branch
  • You've successfully run gulp runtests locally
  • There are new or updated unit tests validating the change

Why a draft PR for stage 1 proposal?

The TypeScript officially follows EcmaScript / stage 3 proposals. However, I'm opening this draft pull request despite it being only stage 1. The partial application and pipeline proposals now are in a stage where they want people to test the features - write it in their code, find problems, test existing codebases. The usual way these would be done is through a Babel plugin, but since a few years ago, just a plain text editor with syntax highlighting is no longer the default JS development environment.

TypeScript is no longer just a build step. It's used by a significant portion of JS developers for all their development, even when prototyping new code. If the tool chain of these developers requires TypeScript, then a simple Babel plugin won't help. This means that writing TypeScript with those features is impossible without first-class support for them in TypeScript.

But then could we ask them to write just plain JS instead? It turns out that TypeScript is more and more part of normal JavaScript development process with Language Server Protocol pointing out errors in code and providing typing information. Having people encounter red squigglies and disappearing type information as soon as they use the new language feature will not count favourably to the user experience. I believe having TypeScript support for new syntax proposals as important or even more important than having a Babel plugin.

I was considering creating and upkeeping a separate fork, but that would just mean duplication of work. There's already a great infrastructure for TypeScript with playgrounds, CI, etc. With a draft PR, new features can more easily get more eyes, testers and feedback. There will eventually be issues and questions on new features for TypeScript and github.com/microsoft/TypeScript is where anyone would first look up info on partial application.

Of course, I'm not expecting merging until the proposal reaches stage 3.

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@typescript-bot typescript-bot added the lib update PR modifies files in the `lib` folder label Apr 15, 2020
@Pokute Pokute marked this pull request as ready for review April 15, 2020 14:06
@Pokute Pokute marked this pull request as draft April 15, 2020 14:06
@orta

This comment has been minimized.

@typescript-bot

This comment has been minimized.

@orta
Copy link
Contributor

orta commented Apr 15, 2020

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 15, 2020

Heya @orta, I've started to run the tarball bundle task on this PR at 15ac42e. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 15, 2020

Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/71368/artifacts?artifactName=tgz&fileId=66B315F01746D1BB7A072158A87E42DB63D7306711F0EE0AEF20182FF008484802&fileName=/typescript-3.9.0-insiders.20200415.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

@ghost
Copy link

ghost commented May 23, 2021

Excuse me, I'm not sure if this PR can still be trivially repacked. If it can, could you please have the bot repack it?

As much as I love the pipeline operator, I actually wish for partial application even more. While not pretty, a pipe function can replicate a pipe operator pretty well; on the other hand, I can't stand partial application done through currying (as is common for TS functional programmers). Curried function signatures are very difficult to read and it's always ambiguous whether a curried function call returns another function or if it returns another data type.

@Pokute
Copy link
Author

Pokute commented May 24, 2021

@alnj Sure enough if there's people enthusiastic about it! It's not trivial to rebase it, but it's not completely terrible either. I might be a bit busy during the start of this week but might have time in latter half. Feel free to message me here and push me forward again If I don't write an update here during this week. :-)

@ghost
Copy link

ghost commented May 24, 2021

I've started writing a project using the pipeline operator and all things considered, even though I would love to experiment with partial application I'm going to continue with the pipeline operator PR for the time being. Eventually that project will be open-source and can serve as a real-world example. Though I'm still learning TypeScript, hopefully I can make something decent.

@orta
Copy link
Contributor

orta commented May 26, 2021

It might work, it might not
@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 26, 2021

Heya @orta, I've started to run the tarball bundle task on this PR at 1c2f3c8. You can monitor the build here.

@Pokute
Copy link
Author

Pokute commented Jun 3, 2021

I spent some time rebasing the code, but there's a couple of tests that fail. I'll check them out later.

@Pokute Pokute force-pushed the partial-application branch from 1c2f3c8 to d9a9aef Compare October 3, 2021 22:39
@Pokute
Copy link
Author

Pokute commented Oct 3, 2021

A new version:

  • Rebased to current main
  • Now supports f~(?, 1) -form as documented in (Syntactic marker for partial application).
  • This is the last version that supports the original f(?, 1) -form of partial application (if the above variant gains traction)
  • Is a lot more complete and has a bit more tests.
  • Should support most of the features of the Syntactic marker proposal variant, but...
  • Doesn't yet support the ... -rest argument.

I will drop the support for the old function-call-like f(?, 1) form next and try to add support for rest (...) arguments.

@orta
Copy link
Contributor

orta commented Oct 4, 2021

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 4, 2021

Heya @orta, I've started to run the tarball bundle task on this PR at d9a9aef. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 4, 2021

Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/112376/artifacts?artifactName=tgz&fileId=611FBEBA38198D5B89FD29473E5A75D46D3971943D4D94559F7FE93A5E459EE102&fileName=/typescript-4.5.0-insiders.20211004.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@4.5.0-pr-37973-15".;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug lib update PR modifies files in the `lib` folder
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants