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 OverloadedLabels support for positional lenses #156

Merged
merged 3 commits into from
Mar 29, 2024

Conversation

amesgen
Copy link
Contributor

@amesgen amesgen commented Apr 18, 2023

Closes #151

@amesgen amesgen force-pushed the positional-labels branch from f7ef335 to 5eddcb1 Compare April 19, 2023 00:04
@@ -271,6 +271,14 @@ tests = TestList $ map mkHUnitTest
, (valLabel ^? #RecB . _1 ) ~=? Just 3
, (valLabel ^? #RecB ) ~=? Just (3, True)
, (valLabel ^? #RecC ) ~=? Nothing

, (valLabel ^. #1 ) ~=? 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

'FieldType
If (StartsWithDigit name)
'PositionType
( If (CmpSymbol "_@" name == 'LT && CmpSymbol "_[" name == 'GT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if these predicates also had names? I guess the reason you pulled out StartsWithDigit is so you can define it conditionally, but it would still make things more consistent to pull out the others too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, added a commit doing that 👍

@@ -144,3 +163,35 @@ instance ( Applicative f, Choice p, Constructor name s t a b
instance ( Applicative f, Choice p, Constructor name s t a b
) => IsLabelHelper 'ConstrType name p f s t a b where
labelOutput = constructorPrism @name

#if MIN_VERSION_base(4,18,0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we actually need this? A comment would help! Looking at the issue, it seems like before 9.6 it is just the case that labels can't start with numbers. If that's all, then the code here is perfectly correct before 9.6, it just won't ever be able to trigger because no label of the correct form can be written in the surface syntax. Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the implementation uses eg UnconsSymbol which is only available since GHC 9.2 (see the "Char kind" GHC proposal), as the implementation before GHC 9.2 is very convoluted, see eg the symbols package.

As this feature is only interesting on GHCs >=9.6, I just made it conditional based on that. In particular, for some reason, the current definition of DigitToNat does not compile on GHC 9.2, only on >=9.4, but it didn't seem necessary to investigate that due to the fact that we only need GHC >=9.6 support.

Changed the condition to #if MIN_VERSION_base(4,17,0) and added a comment 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aha, that makes sense. We could make the pre-9.6 case a TypeError so people get told why it doesn't work, but I don't think that's a big deal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even then, you could leave StartsWithDigit and friends, and just have ParseNat do nothing pre 9.6. Not a big deal, it just can be nice to minimize the amount in the CPP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, done 👍

@amesgen amesgen force-pushed the positional-labels branch from 5eddcb1 to 3475ce6 Compare March 29, 2024 18:26
@michaelpj
Copy link
Collaborator

Oh, and could you add a changelog entry, please?

@amesgen amesgen force-pushed the positional-labels branch from 3475ce6 to 2baf7a3 Compare March 29, 2024 18:44
Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Lovely, thanks!

@michaelpj michaelpj merged commit 09bd6c7 into kcsongor:master Mar 29, 2024
9 checks passed
@amesgen amesgen deleted the positional-labels branch March 29, 2024 18:56
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.

Make use of unrestricted OverloadedLabels
2 participants