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

Difference between CharIn and Either #22

Open
jtrakk opened this issue Mar 25, 2021 · 3 comments
Open

Difference between CharIn and Either #22

jtrakk opened this issue Mar 25, 2021 · 3 comments

Comments

@jtrakk
Copy link

jtrakk commented Mar 25, 2021

What is the difference between CharIn and Either? CharIn isn't restricted to Char types, so that might not be the best name, but maybe both CharIn and Either could be OneOf?

@gkappler
Copy link
Owner

I like your suggested simplification with OneOf but doubt whether eliminating one of the internal implementations is possible without cost -- even though there might be some code-cruft overlap in these types.

The reason is:

  • CharIn is optimized for matching the element (Char) at current index in the sequence only (so requires match length 1 that might span multiple codeunits). A internal ismatch function (that can handle case e.g.) is used and state does not keep track of option #.

  • Either is very general: iterates through all matches of all options, can match longer subsequences, and retains the matching option # and state.

I agree that CharIn is not a good name when other sequences than Strings are parsed. OneOf is catchy, but suggests a Set like representation, and I find it not matching in cases of a predicate function like CharIn(islowercase). Would ElementIn clean up confusion for you?

@jtrakk
Copy link
Author

jtrakk commented Mar 25, 2021

Would ElementIn clean up confusion for you?

Yeah, though it's a bit weird to say ElementIn('x') since 'x' isn't a container. Single('x') is another option. Or maybe this is a case for Just.

@gkappler
Copy link
Owner

With Just I think of Maybe Nothing ;-).

You could say parser('x') in your example.

ElementIn('x', 'y'), ElementIn("xy") make sense, yes?

Doe ValueIn('x', 'y'), ValueIn("xy") make more sense to you?

Another alternative would be to decide what implementation is used in the Either constructor?

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

No branches or pull requests

2 participants