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

Deriving Ord for AlexPosn #233

Closed
Kleidukos opened this issue Apr 30, 2023 · 4 comments · Fixed by #234
Closed

Deriving Ord for AlexPosn #233

Kleidukos opened this issue Apr 30, 2023 · 4 comments · Fixed by #234

Comments

@Kleidukos
Copy link
Member

Kleidukos commented Apr 30, 2023

I'm trying to use Alex with Megaparsec, whose Stream typeclass requires an Ord constraint on the elements of a list or sequence of tokens.

As I pre-lex my source input with Alex and turn it into a Seq of Ranged Tokens making use of AlexPosn for the position, it is the last thing that does not have an Ord instance.

I can provide a patch.

@Kleidukos
Copy link
Member Author

@andreasabel @Ericson2314 Any opinion on this? :)

@andreasabel
Copy link
Member

andreasabel commented May 1, 2023

@Kleidukos An Ord instances for AlexPosn is welcome.

data AlexPosn = AlexPn !Int !Int !Int

The type itself is non-free: the second and third fields (line and column) are determined by the first field (character position).
I think the derived (lexicographic) Ord instance would work nevertheless.
Which implementation did you have in mind?

@Kleidukos
Copy link
Member Author

Yes I was really going on with the basic deriving stock (Ord) at first.

@andreasabel
Copy link
Member

This will be a minor version bump (even though Alex does not have to follow the PVP): add non-orphan instance.

@andreasabel andreasabel added this to the 3.2.8 milestone May 1, 2023
@Kleidukos Kleidukos self-assigned this May 1, 2023
Kleidukos added a commit to Kleidukos/alex that referenced this issue May 1, 2023
andreasabel pushed a commit to Kleidukos/alex that referenced this issue May 14, 2023
@andreasabel andreasabel modified the milestones: 3.2.8, 3.3.0.0 May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants