Summary
Add a replace function for String to base similar to the one for Text in Haskell (see function description on Hackage).
replace : (needle : String) -> (replacement : String) -> (haystack : String) -> String
Motivation
This proposal comes from a discussion which occurred on Zulip.
The proposal
As suggested by @mattpolzin there should be a discussion on how this function should be implemented:
a) using FFIs (for efficiency); or
b) using pack and unpack for simplicity.
At the time being, I have made my own implementation which can be found on Codeberg.
It relies on a replace function for List which definition can be found in this module of the same Codeberg repo.
Of course, there are other ways to do it (more efficient ones/which do not rely on assert_total).
My goal was to come with a simple implementation relying on existing functions.
Alternatives considered
Current situation with my own library
My implementation fits my needs, but the day I want to publish on pack libraries relying on it, I would need to publish this library as well, which only contains a couple of functions.
Internal module
I could have this replace function as an internal module of my libraries, but this is such a common need that I would probably have to implement it multiple times, which is not really ideal in terms of maintenance (considering others may do exactly the same!).
Add it to contrib
This was my first thought, but given the state of affairs, this is not really a solution.
Or it would imply to move first Data.String.Extra and Data.List.Extra to their own package at https://github.com/idris-community as per RFC #2866.
Conclusion
I'm just seeking for a way forward for a better solution than "roll my own package" for such cases.
I also see it as an opportunity to update CONTRIBUTING.md as Idris2 has now a de-facto package manager with pack and things seem to be moving forward with RFC #2866 mentioned above.
Summary
Add a
replacefunction forStringto base similar to the one forTextin Haskell (see function description on Hackage).Motivation
This proposal comes from a discussion which occurred on Zulip.
The proposal
As suggested by @mattpolzin there should be a discussion on how this function should be implemented:
a) using FFIs (for efficiency); or
b) using
packandunpackfor simplicity.At the time being, I have made my own implementation which can be found on Codeberg.
It relies on a
replacefunction forListwhich definition can be found in this module of the same Codeberg repo.Of course, there are other ways to do it (more efficient ones/which do not rely on
assert_total).My goal was to come with a simple implementation relying on existing functions.
Alternatives considered
Current situation with my own library
My implementation fits my needs, but the day I want to publish on
packlibraries relying on it, I would need to publish this library as well, which only contains a couple of functions.Internal module
I could have this
replacefunction as an internal module of my libraries, but this is such a common need that I would probably have to implement it multiple times, which is not really ideal in terms of maintenance (considering others may do exactly the same!).Add it to contrib
This was my first thought, but given the state of affairs, this is not really a solution.
Or it would imply to move first
Data.String.ExtraandData.List.Extrato their own package at https://github.com/idris-community as per RFC #2866.Conclusion
I'm just seeking for a way forward for a better solution than "roll my own package" for such cases.
I also see it as an opportunity to update CONTRIBUTING.md as Idris2 has now a de-facto package manager with
packand things seem to be moving forward with RFC #2866 mentioned above.