Skip to content

Conversation

@ashokkimmel
Copy link

Note, I did not test this.

type family Elem where
Elem (_:xs) x = Elem xs x
Elem '[] _ = 'False
Elem (x':_) x = 'True
Copy link
Owner

Choose a reason for hiding this comment

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

The above two equations match both x:xs and [] cases, so this equation will never be reached. Also, did you intend to assert that x' and x are equivalent? In which case, it should be Elem (x:_) x = True.

Copy link
Author

Choose a reason for hiding this comment

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

I meant to do `Elem (x ': xs) x = 'True

Copy link
Owner

Choose a reason for hiding this comment

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

Ahhh, of course. I tend to avoid ticked promoted constructors except where required to disambiguate. Further reading: https://gitlab.haskell.org/ghc/ghc/-/issues/20531

@raehik
Copy link
Owner

raehik commented Oct 28, 2025

Thanks for this. I think this character predicate better fits with other parsers, which I hadn't implemented yet. I've done so at #5 :

type OneOf :: [Char] -> PParser Char
type OneOf chs = Satisfy (ElemSym chs)

So now you can say:

type ParseOperator = OneOf ['+', '-', '/', '*']

@raehik
Copy link
Owner

raehik commented Oct 28, 2025

I'm considering this implemented. Note that I don't actually export my Elem type family or a defun symbol, because I consider them implementation details. (They should really be provided by a general-purpose type-level programming library. Symparsec relies on singleraeh, I should add them there. Eventually, haha...)

@raehik raehik closed this Oct 28, 2025
@ashokkimmel
Copy link
Author

Thanks for this. I think this character predicate better fits with other parsers, which I hadn't implemented yet. I've done so at #5 :

type OneOf :: [Char] -> PParser Char
type OneOf chs = Satisfy (ElemSym chs)

So now you can say:

type ParseOperator = OneOf ['+', '-', '/', '*']

I was also thinking of a Not combinator, so you could do Not (OneOf ['-,'+','/','*']), or, if OneOf was changed to symbols: Not (OneOf "+-/*"). This would make it so that for Printf, you could just say While (Not (OneOf ['%']) and it would all work out.
I'm just trying to supply the barebones such that all files in Example don't need to mannually define App instances and can just use built in parser combinators. That's why I thought that adding Elem would be good. Want me to give more pull commits? I mainly use a chromebook (which is why I didn't test my code), but I have a PC with which I could clone the repo.

@raehik
Copy link
Owner

raehik commented Oct 29, 2025

OneOf parses a Char. I think you mean something like Satisfy (Not (Elem chs)). megaparsec defines this as noneOf :: [Char] -> Parser Char. I'll add that.

I will gladly accept contributions. Can a Chromebook not run GHC? (GHC supports ARM64.)

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.

2 participants