Created
December 28, 2017 23:03
-
-
Save chris-martin/51e78452a0be6fbf688c33a9a318f24e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | A string we're looking for in the source. | |
-- | |
-- /Mnemonic: "needle in a haystack"/ | |
newtype Needle = Needle Strict.Text | |
deriving Eq | |
-- | Needles are sorted by length with the longest needles first. | |
-- | |
-- We use this ordering when performing replacements. For example, if both | |
-- "a" and "ab" are needles, then we give "ab" a chance to be found /before/ | |
-- "a". Otherwise, "a" would always match first and the "ab" replacement | |
-- would never occur. | |
instance Ord Needle | |
where | |
compare = compare `on` \(Needle x) -> (negate (StrictText.length x), x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment