Visitar URL original
Incorrect `Monoid` instance · Issue #19 · fpco/haskell-filesystem · GitHub
Skip to content

Incorrect Monoid instance #19

Open

Description

@sgf-dma

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 = []}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions