pathtype 0.5.1 → 0.5.2
raw patch · 5 files changed
+74/−85 lines, 5 files
Files
- System/Path.hs +71/−3
- System/Path/Internal.hs +1/−76
- System/Path/Posix.hs +0/−2
- System/Path/Windows.hs +1/−3
- pathtype.cabal +1/−1
System/Path.hs view
@@ -1,11 +1,79 @@ {-# LANGUAGE CPP #-}- -- | This module provides type-safe access to filepath manipulations. ----- It is purely a wrapper for 'System.Path.Windows' or 'System.Path.Posix'--- depending on the platform on which it is compiled.+-- It is designed to be imported instead of "System.FilePath".+-- (It is intended to provide versions of functions from that+-- module which have equivalent functionality but are more+-- typesafe). "System.Path.Directory" is a companion module+-- providing a type-safe alternative to "System.Directory". --+-- The heart of this module is the @'Path' ar fd@ abstract type which+-- represents file and directory paths. The idea is that there are+-- two phantom type parameters - the first should be 'Abs' or 'Rel',+-- and the second 'File' or 'Dir'. A number of type synonyms are+-- provided for common types:+--+-- > type AbsFile = Path Abs File+-- > type RelFile = Path Rel File+-- > type AbsDir = Path Abs Dir+-- > type RelDir = Path Rel Dir+-- >+-- > type AbsPath fd = Path Abs fd+-- > type RelPath fd = Path Rel fd+-- > type FilePath ar = Path ar File+-- > type DirPath ar = Path ar Dir+--+-- The type of the 'combine' (aka '</>') function gives the idea:+--+-- > (</>) :: DirPath ar -> RelPath fd -> Path ar fd+--+-- Together this enables us to give more meaningful types to+-- a lot of the functions, and (hopefully) catch a bunch more+-- errors at compile time.+--+-- Overloaded string literals are supported, so with the @OverloadedStrings@+-- extension enabled, you can:+--+-- > f :: FilePath ar+-- > f = "tmp" </> "someFile" <.> "ext"+--+-- If you don't want to use @OverloadedStrings@, you can use the construction fns:+--+-- > f :: FilePath ar+-- > f = asDirPath "tmp" </> asFilePath "someFile" <.> "ext"+--+-- or...+--+-- > f :: FilePath ar+-- > f = asPath "tmp" </> asPath "someFile" <.> "ext"+--+-- or just...+--+-- > f :: FilePath ar+-- > f = asPath "tmp/someFile.ext"+--+-- One point to note is that whether one of these is interpreted as+-- an absolute or a relative path depends on the type at which it is+-- used:+--+-- > *System.Path> f :: AbsFile+-- > /tmp/someFile.ext+-- > *System.Path> f :: RelFile+-- > tmp/someFile.ext+--+-- You will typically want to import as follows:+--+-- > import Prelude hiding (FilePath)+-- > import System.Path+-- > import System.Path.Directory+-- > import System.Path.IO+--+-- The basic API (and properties satisfied) are heavily influenced+-- by Neil Mitchell's "System.FilePath" module.+--+-- -- Ben Moseley - (c) 2009-2010+-- #if defined(mingw32_HOST_OS) || defined(__MINGW32__) module System.Path(module System.Path.Windows) where
System/Path/Internal.hs view
@@ -1,80 +1,5 @@--- LANGUAGE pragmas need to go in System.Path.[Windows|Posix] --- | This module provides type-safe access to filepath manipulations.------ It is designed to be imported instead of "System.FilePath".--- (It is intended to provide versions of functions from that--- module which have equivalent functionality but are more--- typesafe). "System.Path.Directory" is a companion module--- providing a type-safe alternative to "System.Directory".------ The heart of this module is the @'Path' ar fd@ abstract type which--- represents file and directory paths. The idea is that there are--- two phantom type parameters - the first should be 'Abs' or 'Rel',--- and the second 'File' or 'Dir'. A number of type synonyms are--- provided for common types:------ > type AbsFile = Path Abs File--- > type RelFile = Path Rel File--- > type AbsDir = Path Abs Dir--- > type RelDir = Path Rel Dir--- >--- > type AbsPath fd = Path Abs fd--- > type RelPath fd = Path Rel fd--- > type FilePath ar = Path ar File--- > type DirPath ar = Path ar Dir------ The type of the 'combine' (aka '</>') function gives the idea:------ > (</>) :: DirPath ar -> RelPath fd -> Path ar fd------ Together this enables us to give more meaningful types to--- a lot of the functions, and (hopefully) catch a bunch more--- errors at compile time.------ Overloaded string literals are supported, so with the @OverloadedStrings@--- extension enabled, you can:------ > f :: FilePath ar--- > f = "tmp" </> "someFile" <.> "ext"------ If you don't want to use @OverloadedStrings@, you can use the construction fns:------ > f :: FilePath ar--- > f = asDirPath "tmp" </> asFilePath "someFile" <.> "ext"------ or...------ > f :: FilePath ar--- > f = asPath "tmp" </> asPath "someFile" <.> "ext"------ or just...------ > f :: FilePath ar--- > f = asPath "tmp/someFile.ext"------ One point to note is that whether one of these is interpreted as--- an absolute or a relative path depends on the type at which it is--- used:------ > *System.Path> f :: AbsFile--- > /tmp/someFile.ext--- > *System.Path> f :: RelFile--- > tmp/someFile.ext------ You will typically want to import as follows:------ > import Prelude hiding (FilePath)--- > import System.Path--- > import System.Path.Directory--- > import System.Path.IO------ The basic API (and properties satisfied) are heavily influenced--- by Neil Mitchell's "System.FilePath" module.--------- Ben Moseley - (c) 2009-2010---+-- LANGUAGE pragmas need to go in System.Path.[Windows|Posix] module System.Path.MODULE_NAME ( -- * The main filepath (& dirpath) abstract type
System/Path/Posix.hs view
@@ -10,8 +10,6 @@ -- However, importing this explicitly allows for manipulation of -- non-native paths. ----- Ben Moseley - (c) 2009-2010- #ifdef __HADDOCK__ module System.Path.Posix where #else
System/Path/Windows.hs view
@@ -10,10 +10,8 @@ -- However, importing this explicitly allows for manipulation of -- non-native paths. ----- Ben Moseley - (c) 2009-2010- #ifdef __HADDOCK__-module System.Path.Posix where+module System.Path.Windows where #else #include "Internal.hs" #endif
pathtype.cabal view
@@ -1,5 +1,5 @@ Name: pathtype-Version: 0.5.1+Version: 0.5.2 Synopsis: Type-safe replacement for System.FilePath etc Description: This package provides type-safe access to filepath manipulations. .