Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
A more type-safe version of file paths
This module provides the basic Path
abstraction. See also
System.Path.IO which extends this module by thin wrappers
wrappers around common IO
operations.
- data Path a
- takeDirectory :: Path a -> Path a
- takeFileName :: Path a -> Path Unrooted
- newtype FileExt = FileExt String
- (<.>) :: Path a -> FileExt -> Path a
- (-<.>) :: Path a -> FileExt -> Path a
- splitExtension :: Path a -> (Path a, Maybe FileExt)
- splitExtensions :: Path a -> (Path a, Maybe FileExt)
- takeExtension :: Path a -> Maybe FileExt
- takeExtensions :: Path a -> Maybe FileExt
- takeBaseName :: Path a -> Path Unrooted
- stripExtension :: FileExt -> Path a -> Maybe (Path a)
- isExtensionOf :: FileExt -> Path a -> Bool
- hasTrailingPathSeparator :: Path a -> Bool
- addTrailingPathSeparator :: Path a -> Path a
- dropTrailingPathSeparator :: Path a -> Path a
- data Unrooted
- (</>) :: Path a -> Path Unrooted -> Path a
- unrootPath :: Path root -> Path Unrooted
- toUnrootedFilePath :: Path Unrooted -> FilePath
- fromUnrootedFilePath :: FilePath -> Path Unrooted
- fragment :: String -> Path Unrooted
- fragments :: [String] -> Path Unrooted
- joinFragments :: [Path Unrooted] -> Path Unrooted
- splitFragments :: Path Unrooted -> [Path Unrooted]
- normalise :: Path a -> Path a
- class FsRoot root where
- data FsPath = FsRoot root => FsPath (Path root)
- data CWD
- type Relative = CWD
- data Absolute
- data HomeDir
- toFilePath :: Path Absolute -> FilePath
- fromFilePath :: FilePath -> FsPath
- makeAbsolute :: FsPath -> IO (Path Absolute)
- fromAbsoluteFilePath :: FilePath -> Path Absolute
Paths
Paths
A Path
is a wrapped FilePath
with a type-level tag indicating where this
path is rooted (relative to the current directory, absolute path, relative to
a web domain, whatever). Most operations on Path
are just lifted versions
of the operations on the underlying FilePath
. The tag however allows us to
give a lot of operations a more meaningful type. For instance, it does not
make sense to append two absolute paths together; instead, we can only append
an unrooted path to another path. It also means we avoid bugs where we use
one kind of path where we expect another.
FilePath-like operations on paths with arbitrary roots
takeDirectory :: Path a -> Path a Source #
Wrapped takeDirectory
takeFileName :: Path a -> Path Unrooted Source #
Wrapped takeFileName
Operations aware of file-extensions
Type to represent filepath extensions.
File extensions are usually a high-level convention and in most cases the low-level filesystem layer is agnostic to them.
Since: 0.2.0.0
splitExtension :: Path a -> (Path a, Maybe FileExt) Source #
Wrapped splitExtension
splitExtensions :: Path a -> (Path a, Maybe FileExt) Source #
Wrapped splitExtensions
Since: 0.2.0.0
takeExtension :: Path a -> Maybe FileExt Source #
Wrapped takeExtension
takeExtensions :: Path a -> Maybe FileExt Source #
Wrapped takeExtensions
Since: 0.2.0.0
takeBaseName :: Path a -> Path Unrooted Source #
Wrapped takeBaseName
Since: 0.2.0.0
stripExtension :: FileExt -> Path a -> Maybe (Path a) Source #
Wrapped stripExtension
Since: 0.2.0.0
isExtensionOf :: FileExt -> Path a -> Bool Source #
Wrapped isExtensionOf
Since: 0.2.0.0
Trailing slash functions
hasTrailingPathSeparator :: Path a -> Bool Source #
Wrapped hasTrailingPathSeparator
Since: 0.2.0.0
addTrailingPathSeparator :: Path a -> Path a Source #
Wrapped addTrailingPathSeparator
Since: 0.2.0.0
dropTrailingPathSeparator :: Path a -> Path a Source #
Wrapped dropTrailingPathSeparator
Since: 0.2.0.0
Unrooted paths
Type-level tag for unrooted paths
Unrooted paths need a root before they can be interpreted.
unrootPath :: Path root -> Path Unrooted Source #
Forget a path's root
NOTE: If the original Path
is considered an absolute POSIX style
FilePath, it's automatically converted to a relative FilePath.
toUnrootedFilePath :: Path Unrooted -> FilePath Source #
Convert a relative/unrooted Path to a FilePath (using POSIX style directory separators).
See also toAbsoluteFilePath
fromUnrootedFilePath :: FilePath -> Path Unrooted Source #
Convert from a relative/unrooted FilePath (using POSIX style directory separators).
NOTE: If the argument is considered an absolute POSIX style FilePath, it's automatically converted to a relative FilePath.
fragment :: String -> Path Unrooted Source #
A path fragment (like a single directory or filename)
NOTE: If the argument would be considered an absolute POSIX style FilePath, it's automatically converted to a relative FilePath.
fragments :: [String] -> Path Unrooted Source #
Version of fragment
taking a list of fragments
NOTE: If any argument would be considered an absolute POSIX style FilePath, it's automatically converted to a relative FilePath.
Since: 0.2.0.0
splitFragments :: Path Unrooted -> [Path Unrooted] Source #
Wrapped splitDirectories
Since: 0.2.0.0
File-system paths
class FsRoot root where Source #
A file system root can be interpreted as an (absolute) FilePath
toAbsoluteFilePath :: Path root -> IO FilePath Source #
Convert a Path to an absolute native FilePath (using native style directory separators).
This operation needs to be in IO
for resolving paths with
dynamic roots, such as CWD
or HomeDir
.
See also makeAbsolute
Abstract over a file system root
FsPath
can be constructed directly or via fromFilePath
or fspath
.
Path
tag for paths rooted at the current working directory
Since: 0.2.0.0
Conversions
toFilePath :: Path Absolute -> FilePath Source #
Export absolute path to a native FilePath
.
This is the inverse to fromAbsoluteFilePath
.
fromFilePath :: FilePath -> FsPath Source #
makeAbsolute :: FsPath -> IO (Path Absolute) Source #
Export filesystem path to an absolute Path
See also toAbsoluteFilePath
fromAbsoluteFilePath :: FilePath -> Path Absolute Source #
Construct Absolute
path from a native FilePath
.
This is the inverse to toFilePath
.
NOTE: If the argument is not an absolute path this function will throw an error
.