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

Handle destruct in function arg #10

Merged
merged 7 commits into from
Apr 16, 2024

Conversation

xvw
Copy link

@xvw xvw commented Apr 8, 2024

Supports destruct in the presence of a function parameter.
There are still some unanswered questions. For example, for the moment, the case fun (b: bool) -> will generate fun (true | false : bool). However, fun (_ as b: bool) -> will generate fun ((false as b) | (true as b)) -> . Introducing aliases in the first case seems to me 1, non-trivial and tends towards behavior that's hard to specify when patterns are nested.

@xvw xvw changed the base branch from master to 502-preview April 8, 2024 06:26
@voodoos
Copy link
Owner

voodoos commented Apr 8, 2024

It would be very nice for the review if you could split the changes to have one commit with the refactoring and one with the actual fix, if that makes sense for these changes :-)

(we might also merge the refactoring part to other Merlin's branches)

xvw added 3 commits April 8, 2024 15:36
Fragment the various stages of the `node` function to facilitate
understanding of its flow and the reuse of parts.
@xvw xvw force-pushed the handle-destruct-in-function-arg branch from 8fc4729 to 9f38a32 Compare April 8, 2024 13:44
@xvw
Copy link
Author

xvw commented Apr 8, 2024

Is it better this way?

@voodoos
Copy link
Owner

voodoos commented Apr 8, 2024

Is it better this way?

It's much better, thanks !

@xvw
Copy link
Author

xvw commented Apr 9, 2024

I've added two tests that can handle deconstruction cases on single-field records and single-constructor sums (which seem to be the most trivial use cases for destructing in the presence of function parameters).

@voodoos voodoos self-requested a review April 9, 2024 16:39
"Foo"
],
"notifications": []
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be good to have tests with:

  • A type with one constructor where the constructor has fields.
  • A type with one constructor where the constructor has an inline record
  • A gadt with multiple constructors, but where the types allow only one constructor to be well-typed. (This is harder -- a reach goal.)

Copy link
Author

@xvw xvw Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @goldfirere

  • Works fine
  • As the previous version, it generate Ctor _, but currently, the way that pattern are printed seems wrong. For type t = Foo of {..} it produces Foo_. I am currently investigating on that (it was sed in test mistake from my side. Fixed now)
  • With GADT it seems working too

@xvw xvw force-pushed the handle-destruct-in-function-arg branch from 8f25c63 to 86e76b3 Compare April 10, 2024 13:54
Copy link
Owner

@voodoos voodoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @xvw, thank you !

The fix is surprisingly self contained once the refactoring is moved away :-)

Copy link
Owner

@voodoos voodoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a nice improvement over the current situation, thanks a lot !

@voodoos voodoos merged commit 884c078 into voodoos:502-preview Apr 16, 2024
0 of 2 checks passed
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.

3 participants