paths-0.1: Library for representing and manipulating type-safe file paths

Safe HaskellSafe
LanguageHaskell2010

System.Path

Contents

Description

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.

Synopsis

Paths

newtype Path a Source #

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.

Constructors

Path FilePath 

Instances

Eq (Path a) Source # 

Methods

(==) :: Path a -> Path a -> Bool #

(/=) :: Path a -> Path a -> Bool #

Ord (Path a) Source # 

Methods

compare :: Path a -> Path a -> Ordering #

(<) :: Path a -> Path a -> Bool #

(<=) :: Path a -> Path a -> Bool #

(>) :: Path a -> Path a -> Bool #

(>=) :: Path a -> Path a -> Bool #

max :: Path a -> Path a -> Path a #

min :: Path a -> Path a -> Path a #

Show (Path a) Source # 

Methods

showsPrec :: Int -> Path a -> ShowS #

show :: Path a -> String #

showList :: [Path a] -> ShowS #

NFData (Path a) Source # 

Methods

rnf :: Path a -> () #

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

(<.>) :: Path a -> String -> Path a Source #

Wrapped <.>

Unrooted paths

data Unrooted Source #

Type-level tag for unrooted paths

Unrooted paths need a root before they can be interpreted.

(</>) :: Path a -> Path Unrooted -> Path a Source #

Wrapped </>

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).

fragment :: String -> Path Unrooted Source #

A path fragment (like a single directory or filename)

File-system paths

class FsRoot root where Source #

A file system root can be interpreted as an (absolute) FilePath

Minimal complete definition

toAbsoluteFilePath

Methods

toAbsoluteFilePath :: Path root -> IO FilePath Source #

Convert a Path to an absolute FilePath (using native style directory separators).

data FsPath Source #

Abstract over a file system root

see fromFilePath

Constructors

FsRoot root => FsPath (Path root) 

Instances

NFData FsPath Source # 

Methods

rnf :: FsPath -> () #

Conversions