Skip to content

String manipulation functions / generalize list functions? #46

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

Open
phile314 opened this issue Dec 11, 2016 · 2 comments
Open

String manipulation functions / generalize list functions? #46

phile314 opened this issue Dec 11, 2016 · 2 comments

Comments

@phile314
Copy link
Collaborator

phile314 commented Dec 11, 2016

I am currently writing code involving quite a lot of String manipulation, and currently agda-prelude doesn't offer much functionality for plain Strings yet. I can go via List Char, but that will definitely be slower and feels overly complicated just to e.g. split a string.

The question then is how these functions should be added. Should the existing functions in Data.List be generalized and moved to Container.Foldable? What about functions which don't find into any existing class like a monomorphic functor for strings? What about sequence-like methods?

The other option would be to have multiple distinct specialized functions. However, if we use the same
names we have to put them in a separate modules as both Prelude.String and Prelude.List are imported in Prelude. One could also add some kind of prefix to the functions, eg "s" for all String
specializations to get sLength, sDrop etc..

My preference would be to generalize the functions. This would unify the functions for all types
and one doesn't need qualified imports for all the containers data types. The main drawback
is that it complicates the types and it could make type inference harder.

Any thoughts?

Container.Foldable candidates:

  • length
  • null
  • elem
  • sum
  • product
  • maximum
  • minimum
  • any
  • all

Sequence-like methods:

  • take
  • drop
  • filter
  • isPrefixOf
@UlfNorell
Copy link
Owner

String isn't a functor so how will generalise list functions to Foldable help?

@phile314
Copy link
Collaborator Author

phile314 commented Dec 13, 2016

True, that doesn't help for String. It should read MonoFoldable instead of Foldable, where MonoFoldable is the monomorphic version of Foldable. I think I will try this out in my fork and see how usable it is.

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