Skip to content
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

Incorrect Monoid instance #19

Open
sgf-dma opened this issue Aug 1, 2017 · 0 comments
Open

Incorrect Monoid instance #19

sgf-dma opened this issue Aug 1, 2017 · 0 comments

Comments

@sgf-dma
Copy link

sgf-dma commented Aug 1, 2017

Hi.

Monoid instance of FilePath is incorrect:

> let x = F.decodeString "/a/b" in x `mappend` mempty == x
False

It seems, the reason is append (lib/Filesystem/Path.hs):

171 append :: FilePath -> FilePath -> FilePath
172 append x y = cased where
173         cased = case pathRoot y of
174                 Just RootPosix -> y
175                 Just RootWindowsVolume{} -> y
176                 Just RootWindowsCurrentVolume -> case pathRoot x of
177                         Just RootWindowsVolume{} -> y { pathRoot = pathRoot x }
178                         _ -> y
179                 Just RootWindowsUnc{} -> y
180                 Just RootWindowsDoubleQMark -> y
181                 Nothing -> xy
182         xy = y
183                 { pathRoot = pathRoot x
184                 , pathDirectories = directories
185                 }
186         directories = xDirectories ++ pathDirectories y
187         xDirectories = (pathDirectories x ++) $ if null (filename x)
188                 then []
189                 else [filenameChunk x]
190

in xDirectories, which adds filename of x to the directories of resulting
FilePath. Here is the result with modified Show instance:

> decodeString posix  "/a/b/c"
FilePath {pathRoot = Just RootPosix, pathDirectories = ["a","b"], pathBasename = Just "c", pathExtensions = []}

> decodeString posix  "/a/b/c" `mappend` empty
FilePath {pathRoot = Just RootPosix, pathDirectories = ["a","b","c"], pathBasename = Nothing, pathExtensions = []}
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

1 participant