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

[new] Allow pattern matching in lambdas, and compile constructors #22

Merged
merged 16 commits into from
Aug 7, 2024

Conversation

croyzor
Copy link
Collaborator

@croyzor croyzor commented Aug 7, 2024

Allow lambda expressions to have multiple clauses employing pattern matching logic just like what is done for top level definitions. This improves expressiveness as previously we couldn't pattern match in kernels that were defined as lambdas created by classical functions.

These multi-clause lambda expressions - "multilambdas" - are parsed inside curly braces, as many lambda expressions separated by a |.

Closes #8, #17

@croyzor croyzor requested a review from acl-cqc August 7, 2024 13:59
@croyzor croyzor linked an issue Aug 7, 2024 that may be closed by this pull request
@@ -419,6 +487,73 @@ check' (Simple tm) ((), ((hungry, ty):unders)) = do
pure (((), ()), ((), unders))
check' tm _ = error $ "check' " ++ show tm


-- Clauses from either function definitions or case statements (TODO), as we get
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think this TODO is bogus now? The TODO was this PR! :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

qpred None = Nothing
qpred One = Just None
qpred Tons = Just Tons
data Quantity = None | One | Tons deriving (Enum, Show)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some day we can move this, but let's not bother now

@croyzor croyzor changed the title [new] Allow pattern matching in lambdas [new] Allow pattern matching in lambdas + compile constructors Aug 7, 2024
@acl-cqc acl-cqc changed the title [new] Allow pattern matching in lambdas + compile constructors [new] Allow pattern matching in lambdas, and compile constructors Aug 7, 2024
Copy link
Collaborator

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

🎉 🚀

@croyzor croyzor merged commit ed58724 into main Aug 7, 2024
1 check passed
@croyzor croyzor deleted the multilambda branch August 7, 2024 16:49
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.

Compile constructors feat: Add case statements to BRAT
2 participants