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

Generalize StringLike? #58

Closed
safareli opened this issue May 8, 2017 · 3 comments
Closed

Generalize StringLike? #58

safareli opened this issue May 8, 2017 · 3 comments

Comments

@safareli
Copy link
Contributor

safareli commented May 8, 2017

Currently StringLike is implemented by String and looks like it was in mind to only allowe structures which contain some Chars.

But I think it could be easily changed to support arbitrary containers of arbitrary data.
for example one might define some sumtype Data Color = Red | Blue| Orange ... and have wants to parse List Color into some other structure or maybe even in itself and just validate that colors in the List are in correct order or whatever.

But the StringLike is limiting this kind of use.
What i think is that the class could be changed to:

class StringLike f where
  drop :: forall a. Int -> f a -> f a
  indexOf :: forall a. f a -> f a -> Maybe Int
  null :: forall a. f a -> Boolean
  uncons :: forall a.  f a -> Maybe { head :: a, tail :: f a }

This way one could implement StringLike for List/Array ... and for example anyChar will change to

anyChar :: forall f s m. StringLike f => Monad m => ParserT (f s) m s
@paf31
Copy link
Contributor

paf31 commented May 8, 2017

I'm not sure I like the type of indexOf there. I'd rather use a fundep for the String -> Char dependency, and break indexOf out into its own class if need be.

@safareli
Copy link
Contributor Author

safareli commented May 9, 2017

what about uncons? Char is hardcoded in head

@jamesdbrock
Copy link
Member

Deleted the StringLike class in v7.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants