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
Add the function stripExtension
#43
Comments
Hmm, interesting thought. I'm not changing any code in the repo until a few weeks after the GHC 7.10 release, but time to think about it before then. I'm not super happy about the empty string being so different - it seems a weird special case. At the moment it always removes one dot at least, unless you pass the empty string. That said I can't help but feel |
I like that "it removes at least one dot, or Nothing" rule.
I see 2 problems:
Related: the number of bugs I've discovered in GHC because of improper mangling of |
OK, I'm getting slowly more convinced :). Shouldn't Glad to hear that filepath is eliminating some GHC bugs, indeed, string mangling is hard to get right, especially given the weirdness of filepaths in the wild. |
Getting back to this.
That could work. The rule being that it doesn't matter whether you prepend the extension with a dot or not.
I would then perhaps say
This would also give us the easy to remember/explain "it removes at least one dot, or returns Nothing" rule. |
My thought about That said, I'm not totally convinced. |
Below are 4 pairs of properties. For each pair, the first property is for when we special-case the empty string ( -- 1. It doesn't matter whether you prepend the extension with a dot or not:
null x || head x /= '.' && stripExtension x y == stripExtension ('.':x) y || x == "." || stripExtension x y == stripExtension (tail x) y
(null x || head x /= '.') && stripExtension x y == stripExtension ('.':x) y || stripExtension x y == stripExtension (tail x) y
-- 2. (If the extension is not empty), it removes at least one dot, or returns Nothing:
fmap (filter isExtSeparator) (stripExtension x y) /= Just (filter isExtSeparator y) || null x
fmap (filter isExtSeparator) (stripExtension x y) /= Just (filter isExtSeparator y)
-- 3.
fmap (`addExtension` (takeExtension x)) (stripExtension (takeExtension x) x) == Just x
fmap (`addExtension` (takeExtension x)) (stripExtension (takeExtension x) x) == Just x || null (takeExtension x)
-- 4.
fromJust (stripExtension (takeExtension x) x) == dropExtension x
fromMaybe x (stripExtension (takeExtension x) x) == dropExtension x So properties 3&4 are shorter when we special case the empty string, and properties 1&2 are shorter when we don't. |
Added. Thinking more, I decided that the extension |
I think stripping an empty extension should return Just the original FilePath, for consistency with
stripPrefix
(andstripSuffix
). If however it should return Nothing, then the laws could be changed to:The text was updated successfully, but these errors were encountered: