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.
- newtype Path a = Path FilePath
- castRoot :: Path root -> Path root'
- takeDirectory :: Path a -> Path a
- takeFileName :: Path a -> String
- (<.>) :: Path a -> String -> Path a
- splitExtension :: Path a -> (Path a, String)
- takeExtension :: Path a -> String
- data Unrooted
- (</>) :: Path a -> Path Unrooted -> Path a
- rootPath :: Path Unrooted -> Path root
- unrootPath :: Path root -> Path Unrooted
- toUnrootedFilePath :: Path Unrooted -> FilePath
- fromUnrootedFilePath :: FilePath -> Path Unrooted
- fragment :: String -> Path Unrooted
- joinFragments :: [String] -> Path Unrooted
- splitFragments :: Path Unrooted -> [String]
- class FsRoot root where
- data FsPath = FsRoot root => FsPath (Path root)
- data Relative
- 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 simply a 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.
castRoot :: Path root -> Path root' Source #
Reinterpret the root of a path
This literally just changes the type-level tag; use with caution!
FilePath-like operations on paths with arbitrary roots
takeDirectory :: Path a -> Path a Source #
Wrapped takeDirectory
takeFileName :: Path a -> String Source #
Wrapped takeFileName
splitExtension :: Path a -> (Path a, String) Source #
Wrapped splitExtension
takeExtension :: Path a -> String Source #
Wrapped takeExtension
Unrooted paths
Type-level tag for unrooted paths
Unrooted paths need a root before they can be interpreted.
rootPath :: Path Unrooted -> Path root Source #
Reinterpret an unrooted path
This is an alias for castRoot
; see comments there.
unrootPath :: Path root -> Path Unrooted Source #
Forget a path's root
This is an alias for castRoot
; see comments there.
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).
splitFragments :: Path Unrooted -> [String] Source #
Wrapped splitDirectories
File-system paths
class FsRoot root where Source #
A file system root can be interpreted as an (absolute) FilePath
Abstract over a file system root
see fromFilePath
Conversions
fromFilePath :: FilePath -> FsPath Source #