-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Support for well-typed paths -- -- Support for well-typed paths. @package path @version 0.7.1 -- | Internal types and functions. module Path.Internal -- | Path of some base and type. -- -- The type variables are: -- --
-- [absdir|/|] -- -- [absdir|/home/chris|] ---- -- Remember: due to the nature of absolute paths a path like -- [absdir|/home/chris|] may compile on your platform, but it -- may not compile on another platform (Windows). absdir :: QuasiQuoter -- | Construct a Path Rel Dir using QuasiQuotes. -- --
-- [absdir|/home|]</>[reldir|chris|] --reldir :: QuasiQuoter -- | Construct a Path Abs File using QuasiQuotes. -- --
-- [absfile|/home/chris/foo.txt|] ---- -- Remember: due to the nature of absolute paths a path like -- [absdir|/home/chris/foo.txt|] may compile on your platform, -- but it may not compile on another platform (Windows). absfile :: QuasiQuoter -- | Construct a Path Rel File using QuasiQuotes. -- --
-- [absdir|/home/chris|]</>[relfile|foo.txt|] --relfile :: QuasiQuoter -- | Append two paths. -- -- The following cases are valid and the equalities hold: -- --
-- $(mkAbsDir x) </> $(mkRelDir y) = $(mkAbsDir (x ++ "/" ++ y)) ---- --
-- $(mkAbsDir x) </> $(mkRelFile y) = $(mkAbsFile (x ++ "/" ++ y)) ---- --
-- $(mkRelDir x) </> $(mkRelDir y) = $(mkRelDir (x ++ "/" ++ y)) ---- --
-- $(mkRelDir x) </> $(mkRelFile y) = $(mkRelFile (x ++ "/" ++ y)) ---- -- The following are proven not possible to express: -- --
-- $(mkAbsFile …) </> x ---- --
-- $(mkRelFile …) </> x ---- --
-- x </> $(mkAbsFile …) ---- --
-- x </> $(mkAbsDir …) --(>) :: Path b Dir -> Path Rel t -> Path b t infixr 5 > -- | If the directory in the first argument is a proper prefix of the path -- in the second argument strip it from the second argument, generating a -- path relative to the directory. Throws NotAProperPrefix if the -- directory is not a proper prefix of the path. -- -- The following properties hold: -- --
-- stripProperPrefix x (x </> y) = y ---- -- Cases which are proven not possible: -- --
-- stripProperPrefix (a :: Path Abs …) (b :: Path Rel …) ---- --
-- stripProperPrefix (a :: Path Rel …) (b :: Path Abs …) ---- -- In other words the bases must match. stripProperPrefix :: MonadThrow m => Path b Dir -> Path b t -> m (Path Rel t) -- | Determines if the path in the first parameter is a proper prefix of -- the path in the second parameter. -- -- The following properties hold: -- --
-- not (x `isProperPrefixOf` x) ---- --
-- x `isProperPrefixOf` (x </> y) --isProperPrefixOf :: Path b Dir -> Path b t -> Bool -- | Take the parent path component from a path. -- -- The following properties hold: -- --
-- parent (x </> y) == x -- parent "/x" == "/" -- parent "x" == "." ---- -- On the root (absolute or relative), getting the parent is idempotent: -- --
-- parent "/" = "/" -- parent "." = "." --parent :: Path b t -> Path b Dir -- | Extract the file part of a path. -- -- The following properties hold: -- --
-- filename (p </> a) == filename a --filename :: Path b File -> Path Rel File -- | Extract the last directory name of a path. -- -- The following properties hold: -- --
-- dirname $(mkRelDir ".") == $(mkRelDir ".") ---- --
-- dirname (p </> a) == dirname a --dirname :: Path b Dir -> Path Rel Dir -- | Add extension to given file path. -- --
-- >>> addExtension ".foo" $(mkRelFile "name" ) == Just $(mkRelFile "name.foo" ) -- -- >>> addExtension ".foo." $(mkRelFile "name" ) == Just $(mkRelFile "name.foo." ) -- -- >>> addExtension ".foo.." $(mkRelFile "name" ) == Just $(mkRelFile "name.foo.." ) -- -- >>> addExtension ".foo" $(mkRelFile "name.bar" ) == Just $(mkRelFile "name.bar.foo") -- -- >>> addExtension ".foo" $(mkRelFile ".name" ) == Just $(mkRelFile ".name.foo" ) -- -- >>> addExtension ".foo" $(mkRelFile "name." ) == Just $(mkRelFile "name..foo" ) -- -- >>> addExtension ".foo" $(mkRelFile "..." ) == Just $(mkRelFile "....foo" ) ---- -- Throws an InvalidExtension exception if the extension is not -- valid. A valid extension starts with a . followed by one or -- more characters not including . followed by zero or more -- . in trailing position. Moreover, an extension must be a -- valid filename, notably it cannot include path separators. -- Particularly, .foo.bar is an invalid extension, instead you -- have to first set .foo and then .bar individually. -- Some examples of invalid extensions are: -- --
-- >>> addExtension "foo" $(mkRelFile "name") -- -- >>> addExtension "..foo" $(mkRelFile "name") -- -- >>> addExtension ".foo.bar" $(mkRelFile "name") -- -- >>> addExtension ".foo/bar" $(mkRelFile "name") --addExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | splitExtension is the inverse of addExtension. It splits -- the given file path into a valid filename and a valid extension. -- --
-- >>> splitExtension $(mkRelFile "name.foo" ) == Just ($(mkRelFile "name" ), ".foo" ) -- -- >>> splitExtension $(mkRelFile "name.foo." ) == Just ($(mkRelFile "name" ), ".foo." ) -- -- >>> splitExtension $(mkRelFile "name.foo.." ) == Just ($(mkRelFile "name" ), ".foo..") -- -- >>> splitExtension $(mkRelFile "name.bar.foo" ) == Just ($(mkRelFile "name.bar"), ".foo" ) -- -- >>> splitExtension $(mkRelFile ".name.foo" ) == Just ($(mkRelFile ".name" ), ".foo" ) -- -- >>> splitExtension $(mkRelFile "name..foo" ) == Just ($(mkRelFile "name." ), ".foo" ) -- -- >>> splitExtension $(mkRelFile "....foo" ) == Just ($(mkRelFile "..." ), ".foo" ) ---- -- Throws HasNoExtension exception if the filename does not have -- an extension or in other words it cannot be split into a valid -- filename and a valid extension. The following cases throw an -- exception, please note that "." and ".." are not valid filenames: -- --
-- >>> splitExtension $(mkRelFile "name" ) -- -- >>> splitExtension $(mkRelFile "name." ) -- -- >>> splitExtension $(mkRelFile "name.." ) -- -- >>> splitExtension $(mkRelFile ".name" ) -- -- >>> splitExtension $(mkRelFile "..name" ) -- -- >>> splitExtension $(mkRelFile "...name") ---- -- splitExtension and addExtension are inverses of each -- other, the following laws hold: -- --
-- uncurry addExtension . swap >=> splitExtension == return -- splitExtension >=> uncurry addExtension . swap == return --splitExtension :: MonadThrow m => Path b File -> m (Path b File, String) -- | Get extension from given file path. Throws HasNoExtension -- exception if the file does not have an extension. The following laws -- hold: -- --
-- flip addExtension file >=> fileExtension == return -- fileExtension == (fmap snd) . splitExtension --fileExtension :: MonadThrow m => Path b File -> m String -- | If the file has an extension replace it with the given extension -- otherwise add the new extension to it. Throws an -- InvalidExtension exception if the new extension is not a valid -- extension (see fileExtension for validity rules). -- -- The following law holds: -- --
-- (fileExtension >=> flip replaceExtension file) file == return file --replaceExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | Convert an absolute FilePath to a normalized absolute dir -- Path. -- -- Throws: InvalidAbsDir when the supplied path: -- --
-- >>> addFileExtension "txt $(mkRelFile "foo") -- "foo.txt" -- -- >>> addFileExtension "symbols" $(mkRelFile "Data.List") -- "Data.List.symbols" -- -- >>> addFileExtension ".symbols" $(mkRelFile "Data.List") -- "Data.List.symbols" -- -- >>> addFileExtension "symbols" $(mkRelFile "Data.List.") -- "Data.List..symbols" -- -- >>> addFileExtension ".symbols" $(mkRelFile "Data.List.") -- "Data.List..symbols" -- -- >>> addFileExtension "evil/" $(mkRelFile "Data.List") -- *** Exception: InvalidRelFile "Data.List.evil/" ---- | Deprecated: Please use addExtension instead. addFileExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | A synonym for addFileExtension in the form of an infix -- operator. See more examples there. -- --
-- >>> $(mkRelFile "Data.List") <.> "symbols" -- "Data.List.symbols" -- -- >>> $(mkRelFile "Data.List") <.> "evil/" -- *** Exception: InvalidRelFile "Data.List.evil/" ---- | Deprecated: Please use addExtension instead. (<.>) :: MonadThrow m => Path b File -> String -> m (Path b File) infixr 7 <.> -- | Replace/add extension to given file path. Throws if the resulting -- filename does not parse. -- | Deprecated: Please use replaceExtension instead. setFileExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | A synonym for setFileExtension in the form of an operator. -- | Deprecated: Please use replaceExtension instead. (-<.>) :: MonadThrow m => Path b File -> String -> m (Path b File) infixr 7 -<.> instance GHC.Classes.Ord (Path.Posix.SomeBase t) instance GHC.Classes.Eq (Path.Posix.SomeBase t) instance GHC.Generics.Generic (Path.Posix.SomeBase t) instance GHC.Classes.Eq Path.Posix.PathException instance GHC.Show.Show Path.Posix.PathException instance Control.DeepSeq.NFData (Path.Posix.SomeBase t) instance GHC.Show.Show (Path.Posix.SomeBase t) instance Data.Aeson.Types.ToJSON.ToJSON (Path.Posix.SomeBase t) instance Data.Hashable.Class.Hashable (Path.Posix.SomeBase t) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Posix.SomeBase Path.Posix.Dir) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Posix.SomeBase Path.Posix.File) instance GHC.Exception.Type.Exception Path.Posix.PathException instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Posix.Abs Path.Posix.Dir) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Posix.Rel Path.Posix.Dir) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Posix.Abs Path.Posix.Dir) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Posix.Rel Path.Posix.Dir) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Posix.Abs Path.Posix.File) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Posix.Rel Path.Posix.File) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Posix.Abs Path.Posix.File) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Posix.Rel Path.Posix.File) -- | This library provides a well-typed representation of paths in a -- filesystem directory tree. -- -- Both Path.Posix and Path.Windows provide the same -- interface. This module will reexport the appropriate module for your -- platform. module Path -- | This library provides a well-typed representation of paths in a -- filesystem directory tree. -- -- Note: This module is for working with Windows style paths. -- Importing Path is usually better. -- -- A path is represented by a number of path components separated by a -- path separator which is a / on POSIX systems and can be a -- / or \ on Windows. The root of the tree is -- represented by a / on POSIX and a drive letter followed by a -- / or \ on Windows (e.g. C:\). Paths can be -- absolute or relative. An absolute path always starts from the root of -- the tree (e.g. /x/y) whereas a relative path never starts -- with the root (e.g. x/y). Just like we represent the notion -- of an absolute root by "/", the same way we represent the -- notion of a relative root by ".". The relative root denotes -- the directory which contains the first component of a relative path. module Path.Windows -- | Path of some base and type. -- -- The type variables are: -- --
-- [absdir|/|] -- -- [absdir|/home/chris|] ---- -- Remember: due to the nature of absolute paths a path like -- [absdir|/home/chris|] may compile on your platform, but it -- may not compile on another platform (Windows). absdir :: QuasiQuoter -- | Construct a Path Rel Dir using QuasiQuotes. -- --
-- [absdir|/home|]</>[reldir|chris|] --reldir :: QuasiQuoter -- | Construct a Path Abs File using QuasiQuotes. -- --
-- [absfile|/home/chris/foo.txt|] ---- -- Remember: due to the nature of absolute paths a path like -- [absdir|/home/chris/foo.txt|] may compile on your platform, -- but it may not compile on another platform (Windows). absfile :: QuasiQuoter -- | Construct a Path Rel File using QuasiQuotes. -- --
-- [absdir|/home/chris|]</>[relfile|foo.txt|] --relfile :: QuasiQuoter -- | Append two paths. -- -- The following cases are valid and the equalities hold: -- --
-- $(mkAbsDir x) </> $(mkRelDir y) = $(mkAbsDir (x ++ "/" ++ y)) ---- --
-- $(mkAbsDir x) </> $(mkRelFile y) = $(mkAbsFile (x ++ "/" ++ y)) ---- --
-- $(mkRelDir x) </> $(mkRelDir y) = $(mkRelDir (x ++ "/" ++ y)) ---- --
-- $(mkRelDir x) </> $(mkRelFile y) = $(mkRelFile (x ++ "/" ++ y)) ---- -- The following are proven not possible to express: -- --
-- $(mkAbsFile …) </> x ---- --
-- $(mkRelFile …) </> x ---- --
-- x </> $(mkAbsFile …) ---- --
-- x </> $(mkAbsDir …) --(>) :: Path b Dir -> Path Rel t -> Path b t infixr 5 > -- | If the directory in the first argument is a proper prefix of the path -- in the second argument strip it from the second argument, generating a -- path relative to the directory. Throws NotAProperPrefix if the -- directory is not a proper prefix of the path. -- -- The following properties hold: -- --
-- stripProperPrefix x (x </> y) = y ---- -- Cases which are proven not possible: -- --
-- stripProperPrefix (a :: Path Abs …) (b :: Path Rel …) ---- --
-- stripProperPrefix (a :: Path Rel …) (b :: Path Abs …) ---- -- In other words the bases must match. stripProperPrefix :: MonadThrow m => Path b Dir -> Path b t -> m (Path Rel t) -- | Determines if the path in the first parameter is a proper prefix of -- the path in the second parameter. -- -- The following properties hold: -- --
-- not (x `isProperPrefixOf` x) ---- --
-- x `isProperPrefixOf` (x </> y) --isProperPrefixOf :: Path b Dir -> Path b t -> Bool -- | Take the parent path component from a path. -- -- The following properties hold: -- --
-- parent (x </> y) == x -- parent "/x" == "/" -- parent "x" == "." ---- -- On the root (absolute or relative), getting the parent is idempotent: -- --
-- parent "/" = "/" -- parent "." = "." --parent :: Path b t -> Path b Dir -- | Extract the file part of a path. -- -- The following properties hold: -- --
-- filename (p </> a) == filename a --filename :: Path b File -> Path Rel File -- | Extract the last directory name of a path. -- -- The following properties hold: -- --
-- dirname $(mkRelDir ".") == $(mkRelDir ".") ---- --
-- dirname (p </> a) == dirname a --dirname :: Path b Dir -> Path Rel Dir -- | Add extension to given file path. -- --
-- >>> addExtension ".foo" $(mkRelFile "name" ) == Just $(mkRelFile "name.foo" ) -- -- >>> addExtension ".foo." $(mkRelFile "name" ) == Just $(mkRelFile "name.foo." ) -- -- >>> addExtension ".foo.." $(mkRelFile "name" ) == Just $(mkRelFile "name.foo.." ) -- -- >>> addExtension ".foo" $(mkRelFile "name.bar" ) == Just $(mkRelFile "name.bar.foo") -- -- >>> addExtension ".foo" $(mkRelFile ".name" ) == Just $(mkRelFile ".name.foo" ) -- -- >>> addExtension ".foo" $(mkRelFile "name." ) == Just $(mkRelFile "name..foo" ) -- -- >>> addExtension ".foo" $(mkRelFile "..." ) == Just $(mkRelFile "....foo" ) ---- -- Throws an InvalidExtension exception if the extension is not -- valid. A valid extension starts with a . followed by one or -- more characters not including . followed by zero or more -- . in trailing position. Moreover, an extension must be a -- valid filename, notably it cannot include path separators. -- Particularly, .foo.bar is an invalid extension, instead you -- have to first set .foo and then .bar individually. -- Some examples of invalid extensions are: -- --
-- >>> addExtension "foo" $(mkRelFile "name") -- -- >>> addExtension "..foo" $(mkRelFile "name") -- -- >>> addExtension ".foo.bar" $(mkRelFile "name") -- -- >>> addExtension ".foo/bar" $(mkRelFile "name") --addExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | splitExtension is the inverse of addExtension. It splits -- the given file path into a valid filename and a valid extension. -- --
-- >>> splitExtension $(mkRelFile "name.foo" ) == Just ($(mkRelFile "name" ), ".foo" ) -- -- >>> splitExtension $(mkRelFile "name.foo." ) == Just ($(mkRelFile "name" ), ".foo." ) -- -- >>> splitExtension $(mkRelFile "name.foo.." ) == Just ($(mkRelFile "name" ), ".foo..") -- -- >>> splitExtension $(mkRelFile "name.bar.foo" ) == Just ($(mkRelFile "name.bar"), ".foo" ) -- -- >>> splitExtension $(mkRelFile ".name.foo" ) == Just ($(mkRelFile ".name" ), ".foo" ) -- -- >>> splitExtension $(mkRelFile "name..foo" ) == Just ($(mkRelFile "name." ), ".foo" ) -- -- >>> splitExtension $(mkRelFile "....foo" ) == Just ($(mkRelFile "..." ), ".foo" ) ---- -- Throws HasNoExtension exception if the filename does not have -- an extension or in other words it cannot be split into a valid -- filename and a valid extension. The following cases throw an -- exception, please note that "." and ".." are not valid filenames: -- --
-- >>> splitExtension $(mkRelFile "name" ) -- -- >>> splitExtension $(mkRelFile "name." ) -- -- >>> splitExtension $(mkRelFile "name.." ) -- -- >>> splitExtension $(mkRelFile ".name" ) -- -- >>> splitExtension $(mkRelFile "..name" ) -- -- >>> splitExtension $(mkRelFile "...name") ---- -- splitExtension and addExtension are inverses of each -- other, the following laws hold: -- --
-- uncurry addExtension . swap >=> splitExtension == return -- splitExtension >=> uncurry addExtension . swap == return --splitExtension :: MonadThrow m => Path b File -> m (Path b File, String) -- | Get extension from given file path. Throws HasNoExtension -- exception if the file does not have an extension. The following laws -- hold: -- --
-- flip addExtension file >=> fileExtension == return -- fileExtension == (fmap snd) . splitExtension --fileExtension :: MonadThrow m => Path b File -> m String -- | If the file has an extension replace it with the given extension -- otherwise add the new extension to it. Throws an -- InvalidExtension exception if the new extension is not a valid -- extension (see fileExtension for validity rules). -- -- The following law holds: -- --
-- (fileExtension >=> flip replaceExtension file) file == return file --replaceExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | Convert an absolute FilePath to a normalized absolute dir -- Path. -- -- Throws: InvalidAbsDir when the supplied path: -- --
-- >>> addFileExtension "txt $(mkRelFile "foo") -- "foo.txt" -- -- >>> addFileExtension "symbols" $(mkRelFile "Data.List") -- "Data.List.symbols" -- -- >>> addFileExtension ".symbols" $(mkRelFile "Data.List") -- "Data.List.symbols" -- -- >>> addFileExtension "symbols" $(mkRelFile "Data.List.") -- "Data.List..symbols" -- -- >>> addFileExtension ".symbols" $(mkRelFile "Data.List.") -- "Data.List..symbols" -- -- >>> addFileExtension "evil/" $(mkRelFile "Data.List") -- *** Exception: InvalidRelFile "Data.List.evil/" ---- | Deprecated: Please use addExtension instead. addFileExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | A synonym for addFileExtension in the form of an infix -- operator. See more examples there. -- --
-- >>> $(mkRelFile "Data.List") <.> "symbols" -- "Data.List.symbols" -- -- >>> $(mkRelFile "Data.List") <.> "evil/" -- *** Exception: InvalidRelFile "Data.List.evil/" ---- | Deprecated: Please use addExtension instead. (<.>) :: MonadThrow m => Path b File -> String -> m (Path b File) infixr 7 <.> -- | Replace/add extension to given file path. Throws if the resulting -- filename does not parse. -- | Deprecated: Please use replaceExtension instead. setFileExtension :: MonadThrow m => String -> Path b File -> m (Path b File) -- | A synonym for setFileExtension in the form of an operator. -- | Deprecated: Please use replaceExtension instead. (-<.>) :: MonadThrow m => Path b File -> String -> m (Path b File) infixr 7 -<.> instance GHC.Classes.Ord (Path.Windows.SomeBase t) instance GHC.Classes.Eq (Path.Windows.SomeBase t) instance GHC.Generics.Generic (Path.Windows.SomeBase t) instance GHC.Classes.Eq Path.Windows.PathException instance GHC.Show.Show Path.Windows.PathException instance Control.DeepSeq.NFData (Path.Windows.SomeBase t) instance GHC.Show.Show (Path.Windows.SomeBase t) instance Data.Aeson.Types.ToJSON.ToJSON (Path.Windows.SomeBase t) instance Data.Hashable.Class.Hashable (Path.Windows.SomeBase t) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Windows.SomeBase Path.Windows.Dir) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Windows.SomeBase Path.Windows.File) instance GHC.Exception.Type.Exception Path.Windows.PathException instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Windows.Abs Path.Windows.Dir) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Windows.Rel Path.Windows.Dir) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Windows.Abs Path.Windows.Dir) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Windows.Rel Path.Windows.Dir) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Windows.Abs Path.Windows.File) instance Data.Aeson.Types.FromJSON.FromJSON (Path.Internal.Path Path.Windows.Rel Path.Windows.File) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Windows.Abs Path.Windows.File) instance Data.Aeson.Types.FromJSON.FromJSONKey (Path.Internal.Path Path.Windows.Rel Path.Windows.File)