Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the change
Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR.
Currently PureScript generates a quite outdated, lengthy javascript code for sum ADTs:
produces the following JS in
0.15.15
:When comparing the above ADTs (with pattern matching or
if
expressions), the code generated is as follows:produces in
0.15.15
:A better approach would be to use Symbol class, available in all the modern browsers and Node.JS versions:
so that then the pattern matching can make use of equality (which is stricter than
instanceof
):This PR introduces two changes:
Symbol
for sum ADTsinstanceof
This should make the generated JS code more reliable when comparing values and shorter (resulting in smaller bundles).
For parametrized types this would still work as before, generating the old-style code:
and the JS output:
Checklist:
Linked any existing issues or proposals that this pull request should closeUpdated or added relevant documentationAdded a test for the contribution (if applicable)