-- 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.5.9
-- | Internal types and functions.
module Path.Internal
-- | Path of some base and type.
--
-- Internally is a string. The string can be of two formats only:
--
--
-- - File format: file.txt, foo/bar.txt,
-- /foo/bar.txt
-- - Directory format: foo/, /foo/bar/
--
--
-- All directories end in a trailing separator. There are no duplicate
-- path separators //, no .., no ./, no
-- ~/, etc.
newtype Path b t
Path :: FilePath -> Path b t
instance GHC.Classes.Eq (Path.Internal.Path b t)
instance GHC.Classes.Ord (Path.Internal.Path b t)
instance GHC.Show.Show (Path.Internal.Path b t)
instance Control.DeepSeq.NFData (Path.Internal.Path b t)
instance Data.Aeson.Types.Class.ToJSON (Path.Internal.Path b t)
-- | Support for well-typed paths.
module Path
-- | Path of some base and type.
--
-- Internally is a string. The string can be of two formats only:
--
--
-- - File format: file.txt, foo/bar.txt,
-- /foo/bar.txt
-- - Directory format: foo/, /foo/bar/
--
--
-- All directories end in a trailing separator. There are no duplicate
-- path separators //, no .., no ./, no
-- ~/, etc.
data Path b t
-- | An absolute path.
data Abs
-- | A relative path; one without a root. Note that a . as well as
-- any path starting with a .. is not a valid relative path. In
-- other words, a relative path is always strictly under the directory
-- tree to which it is relative.
data Rel
-- | A file path.
data File
-- | A directory path.
data Dir
-- | Convert an absolute FilePath to a normalized absolute dir
-- Path.
--
-- Throws: PathParseException when the supplied path:
--
--
-- - is not an absolute path
-- - contains a .. anywhere in the path
-- - is not a valid path (See isValid)
--
parseAbsDir :: MonadThrow m => FilePath -> m (Path Abs Dir)
-- | Convert a relative FilePath to a normalized relative dir
-- Path.
--
-- Throws: PathParseException when the supplied path:
--
--
-- - is not a relative path
-- - is any of "", . or ..
-- - contains .. anywhere in the path
-- - is not a valid path (See isValid)
--
parseRelDir :: MonadThrow m => FilePath -> m (Path Rel Dir)
-- | Convert an absolute FilePath to a normalized absolute file
-- Path.
--
-- Throws: PathParseException when the supplied path:
--
--
-- - is not an absolute path
-- - has a trailing path separator
-- - contains .. anywhere in the path
-- - is not a valid path (See isValid)
--
parseAbsFile :: MonadThrow m => FilePath -> m (Path Abs File)
-- | Convert a relative FilePath to a normalized relative file
-- Path.
--
-- Throws: PathParseException when the supplied path:
--
--
-- - is not a relative path
-- - has a trailing path separator
-- - is "", . or ..
-- - contains .. anywhere in the path
-- - is not a valid path (See isValid)
--
parseRelFile :: MonadThrow m => FilePath -> m (Path Rel File)
-- | Exception when parsing a location.
data PathParseException
-- | Make a 'Path Abs Dir'.
--
-- Remember: due to the nature of absolute paths this (e.g.
-- /home/foo) may compile on your platform, but it may not
-- compile on another platform (Windows).
mkAbsDir :: FilePath -> Q Exp
-- | Make a 'Path Rel Dir'.
mkRelDir :: FilePath -> Q Exp
-- | Make a 'Path Abs File'.
--
-- Remember: due to the nature of absolute paths this (e.g.
-- /home/foo) may compile on your platform, but it may not
-- compile on another platform (Windows).
mkAbsFile :: FilePath -> Q Exp
-- | Make a 'Path Rel File'.
mkRelFile :: FilePath -> Q Exp
-- | 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
-- | Strip directory from path, making it relative to that directory.
-- Throws Couldn'tStripPrefixDir if directory is not a parent of
-- the path.
--
-- The following properties hold:
--
--
-- stripDir x (x </> y) = y
--
--
-- Cases which are proven not possible:
--
--
-- stripDir (a :: Path Abs …) (b :: Path Rel …)
--
--
--
-- stripDir (a :: Path Rel …) (b :: Path Abs …)
--
--
-- In other words the bases must match.
stripDir :: MonadThrow m => Path b Dir -> Path b t -> m (Path Rel t)
-- | Is p a parent of the given location? Implemented in terms of
-- stripDir. The bases must match.
--
-- The following properties hold:
--
--
-- not (x isParentOf x)
--
--
--
-- x isParentOf (x </> y)
--
isParentOf :: Path b Dir -> Path b t -> Bool
-- | Take the absolute parent directory from the absolute path.
--
-- The following properties hold:
--
--
-- parent (x </> y) == x
--
--
-- On the root, getting the parent is idempotent:
--
--
-- parent (parent "/") = "/"
--
parent :: Path Abs t -> Path Abs 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 (p </> a) == dirname a
--
dirname :: Path b Dir -> Path Rel Dir
-- | Convert to a FilePath type.
--
-- All directories have a trailing slash, so if you want no trailing
-- slash, you can use dropTrailingPathSeparator from the filepath
-- package.
toFilePath :: Path b t -> FilePath
-- | Convert absolute path to directory to FilePath type.
fromAbsDir :: Path Abs Dir -> FilePath
-- | Convert relative path to directory to FilePath type.
fromRelDir :: Path Rel Dir -> FilePath
-- | Convert absolute path to file to FilePath type.
fromAbsFile :: Path Abs File -> FilePath
-- | Convert relative path to file to FilePath type.
fromRelFile :: Path Rel File -> FilePath
instance GHC.Show.Show Path.PathParseException
instance Data.Aeson.Types.Class.FromJSON (Path.Internal.Path Path.Abs Path.File)
instance Data.Aeson.Types.Class.FromJSON (Path.Internal.Path Path.Rel Path.File)
instance Data.Aeson.Types.Class.FromJSON (Path.Internal.Path Path.Abs Path.Dir)
instance Data.Aeson.Types.Class.FromJSON (Path.Internal.Path Path.Rel Path.Dir)
instance GHC.Exception.Exception Path.PathParseException