A case-insensitive MatchCI module without dependencies. #61
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here's a version of MatchCI without the
case-insensitive
dependency. I kindof dislike the
HasCase
andcaselessEq
names, but didn't take time to thinkof any that didn't overlap some other lib's. Keeping them internal (aka not the
first commit on the match-ci branch) helps.
There are actually three commits on this branch. The first adds a class to the
StringLike
module, which may not be desirable. The second moves all changesinto the MatchCI module. The third approach adds a new module
Text.HasCase
with the option of not making it an exposed module.
Here's why I think MatchCI is better than a
toLower :: Tag s -> Tag s
:Match
are necessarily against static names that the clientcode controls. Assuming that the client code can match a
toLower
-ed tagstream against lower-case literal values assumes that the client code
contains the names to be matched. Of course, the client can
toLower
everything, which leads to...
toLower
. Switching to case-insensitive matching becomes as simple asimporting the
MatchCI
module rather thanMatch
.toLower
to make everything work means lower performance. We can besure that the penalty is small, but performance doesn't end at tag parsing.
It is reasonable to assume that almost every opening tag will be matched for
a tag name. While the Match module isn't part of the
bench
routine, any useagainst real-world HTML will require case-insensitive matching. I think that
for this usage (compare once and forget), a local function is probably better
than using the
case-insensitive
package (allocate a lower-case instance ora thunk).