-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-safe replacement for System.FilePath etc -- -- This package provides type-safe access to filepath manipulations. -- -- System.Path is designed to be used 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. @package pathtype @version 0.5.5 -- | This module provides type-safe access to filepath manipulations. -- -- Normally you would import Path (which will use the default -- implementation for the host platform) instead of this. However, -- importing this explicitly allows for manipulation of non-native paths. module System.Path.Windows -- | This is the main filepath abstract datatype data Path ar fd data Abs data Rel data File data Dir 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 -- | This class allows selective behaviour for absolute and relative paths -- and is mostly for internal use. class Private ar => AbsRelClass ar where absRel f g = runAbsRel $ switchAbsRel (AbsRel f) (AbsRel g) -- | See https://wiki.haskell.org/Closed_world_instances for the -- used technique. switchAbsRel :: AbsRelClass ar => f Abs -> f Rel -> f ar -- | Will become a top-level function in future absRel :: AbsRelClass ar => (AbsPath fd -> a) -> (RelPath fd -> a) -> Path ar fd -> a -- | This class allows selective behaviour for file and directory paths and -- is mostly for internal use. class Private fd => FileDirClass fd where fileDir f g = runFileDir $ switchFileDir (FileDirFunc f) (FileDirFunc g) switchFileDir :: FileDirClass fd => f File -> f Dir -> f fd -- | Will become a top-level function in future fileDir :: FileDirClass fd => (FilePath ar -> a) -> (DirPath ar -> a) -> Path ar fd -> a -- | Convert the Path into a plain String as required for OS -- calls. getPathString :: AbsRelClass ar => Path ar fd -> String rootDir :: AbsDir currentDir :: RelDir -- | Use a String as a Path whose type is determined by its -- context. -- --
--   > asPath "/tmp" == "/tmp"
--   > asPath "file.txt" == "file.txt"
--   > isAbsolute (asPath "/tmp" :: AbsDir) == True
--   > isAbsolute (asPath "/tmp" :: RelDir) == False
--   > getPathString (asPath "/tmp" :: AbsDir) == "/tmp"
--   > getPathString (asPath "/tmp" :: RelDir) == "tmp"
--   
asPath :: String -> Path ar fd -- | Use a String as a RelFile. No checking is done. -- --
--   > getPathString (asRelFile "file.txt") == "file.txt"
--   > getPathString (asRelFile "/file.txt") == "file.txt"
--   > getPathString (asRelFile "tmp") == "tmp"
--   > getPathString (asRelFile "/tmp") == "tmp"
--   
asRelFile :: String -> RelFile -- | Use a String as a RelDir. No checking is done. -- --
--   > getPathString (asRelDir ".") == "."
--   > getPathString (asRelDir "file.txt") == "file.txt"
--   > getPathString (asRelDir "/file.txt") == "file.txt"
--   > getPathString (asRelDir "tmp") == "tmp"
--   > getPathString (asRelDir "/tmp") == "tmp"
--   
asRelDir :: String -> RelDir -- | Use a String as an AbsFile. No checking is done. -- --
--   > getPathString (asAbsFile "file.txt") == "/file.txt"
--   > getPathString (asAbsFile "/file.txt") == "/file.txt"
--   > getPathString (asAbsFile "tmp") == "/tmp"
--   > getPathString (asAbsFile "/tmp") == "/tmp"
--   
asAbsFile :: String -> AbsFile -- | Use a String as an AbsDir. No checking is done. -- --
--   > getPathString (asAbsDir "file.txt") == "/file.txt"
--   > getPathString (asAbsDir "/file.txt") == "/file.txt"
--   > getPathString (asAbsDir "tmp") == "/tmp"
--   > getPathString (asAbsDir "/tmp") == "/tmp"
--   
asAbsDir :: String -> AbsDir -- | Use a String as a 'RelPath fd'. No checking is done. asRelPath :: String -> RelPath fd -- | Use a String as an 'AbsPath fd'. No checking is done. asAbsPath :: String -> AbsPath fd -- | Use a String as a 'FilePath ar'. No checking is done. asFilePath :: String -> FilePath ar -- | Use a String as a 'DirPath ar'. No checking is done. asDirPath :: String -> DirPath ar -- | Examines the supplied string and constructs an absolute or relative -- path as appropriate. -- --
--   > mkPathAbsOrRel "/tmp" == Left (asAbsDir "/tmp")
--   > mkPathAbsOrRel  "tmp" == Right (asRelDir "tmp")
--   
mkPathAbsOrRel :: String -> Either (AbsPath fd) (RelPath fd) -- | Searches for a file or directory with the supplied path string and -- returns a File or Dir path as appropriate. If neither -- exists at the supplied path, Nothing is returned. mkPathFileOrDir :: AbsRelClass ar => String -> IO (Maybe (Either (FilePath ar) (DirPath ar))) -- | Convert a String into an AbsPath by interpreting it as -- relative to the supplied directory if necessary. -- --
--   > mkAbsPath "/tmp" "foo.txt" == "/tmp/foo.txt"
--   > mkAbsPath "/tmp" "/etc/foo.txt" == "/etc/foo.txt"
--   
mkAbsPath :: AbsDir -> String -> AbsPath fd -- | Convert a String into an AbsPath by interpreting it as -- relative to the cwd if necessary. mkAbsPathFromCwd :: String -> IO (AbsPath fd) -- | Infix variant of combine. () :: DirPath ar -> RelPath fd -> Path ar fd -- | Infix variant of addExtension. We only allow files (and not -- directories) to have extensions added by this function. This is -- because it's the vastly common case and an attempt to add one to a -- directory will - more often than not - represent an error. We don't -- however want to prevent the corresponding operation on directories, -- and so we provide a function that is more flexible: -- genericAddExtension. (<.>) :: FilePath ar -> String -> FilePath ar -- | Add an extension, even if there is already one there. E.g. -- addExtension "foo.txt" "bat" -> "foo.txt.bat". -- --
--   > addExtension "file.txt" "bib" == "file.txt.bib"
--   > addExtension "file." ".bib" == "file..bib"
--   > addExtension "file" ".bib" == "file.bib"
--   > addExtension "" "bib" == ".bib"
--   > addExtension "" ".bib" == ".bib"
--   > takeFileName (addExtension "" "ext") == ".ext"
--   
addExtension :: FilePath ar -> String -> FilePath ar -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. combine :: DirPath ar -> RelPath fd -> Path ar fd -- | Remove last extension, and the "." preceding it. -- --
--   > dropExtension x == fst (splitExtension x)
--   
dropExtension :: FilePath ar -> FilePath ar -- | Drop all extensions -- --
--   > not $ hasAnExtension (dropExtensions x)
--   
dropExtensions :: FilePath ar -> FilePath ar -- | Synonym for takeDirectory dropFileName :: Path ar fd -> DirPath ar -- | Set the extension of a file, overwriting one if already present. -- --
--   > replaceExtension "file.txt" ".bob" == "file.bob"
--   > replaceExtension "file.txt" "bob" == "file.bob"
--   > replaceExtension "file" ".bob" == "file.bob"
--   > replaceExtension "file.txt" "" == "file"
--   > replaceExtension "file.fred.bob" "txt" == "file.fred.txt"
--   
replaceExtension :: FilePath ar -> String -> FilePath ar replaceBaseName :: Path ar fd -> String -> Path ar fd replaceDirectory :: Path ar1 fd -> DirPath ar2 -> Path ar2 fd replaceFileName :: Path ar fd -> String -> Path ar fd -- | Split on the extension. addExtension is the inverse. -- --
--   > uncurry (<.>) (splitExtension x) == x
--   > uncurry addExtension (splitExtension x) == x
--   > splitExtension "file.txt" == ("file",".txt")
--   > splitExtension "file" == ("file","")
--   > splitExtension "file/file.txt" == ("file/file",".txt")
--   > splitExtension "file.txt/boris" == ("file.txt/boris","")
--   > splitExtension "file.txt/boris.ext" == ("file.txt/boris",".ext")
--   > splitExtension "file/path.txt.bob.fred" == ("file/path.txt.bob",".fred")
--   
splitExtension :: FilePath ar -> (FilePath ar, String) -- | Split on all extensions -- --
--   > splitExtensions "file.tar.gz" == ("file",".tar.gz")
--   
splitExtensions :: FilePath ar -> (FilePath ar, String) -- | Path must not be empty splitFileName :: Path ar fd -> (DirPath ar, RelPath fd) -- | Get the basename of a file -- --
--   > takeBaseName "/tmp/somedir/myfile.txt" == "myfile"
--   > takeBaseName "./myfile.txt" == "myfile"
--   > takeBaseName "myfile.txt" == "myfile"
--   
takeBaseName :: Path ar fd -> RelPath fd takeDirectory :: Path ar fd -> DirPath ar -- | Get the extension of a file, returns "" for no extension, -- .ext otherwise. -- --
--   > takeExtension x == snd (splitExtension x)
--   > takeExtension (addExtension x "ext") == ".ext"
--   > takeExtension (replaceExtension x "ext") == ".ext"
--   
takeExtension :: FilePath ar -> String -- | Get all extensions -- --
--   > takeExtensions "file.tar.gz" == ".tar.gz"
--   
takeExtensions :: FilePath ar -> String -- | Get the filename component of a file path (ie stripping all parent -- dirs) -- --
--   > takeFileName "/tmp/somedir/myfile.txt" == "myfile.txt"
--   > takeFileName "./myfile.txt" == "myfile.txt"
--   > takeFileName "myfile.txt" == "myfile.txt"
--   
takeFileName :: Path ar fd -> RelPath fd -- | Check whether two strings are equal as file paths. -- --
--   > equalFilePath "/tmp/" "/tmp" == True
--   > equalFilePath "/tmp"  "tmp"  == False
--   
equalFilePath :: String -> String -> Bool -- | Constructs a Path from a list of components. -- --
--   > joinPath ["/tmp","someDir","file.txt"] == "/tmp/someDir/file.txt"
--   > joinPath ["/tmp","someDir","file.txt"] == asRelFile "tmp/someDir/file.txt"
--   
joinPath :: [String] -> Path ar fd -- | Currently just transforms: -- --
--   > normalise "/tmp/fred/./jim/./file" == "/tmp/fred/jim/file"
--   
normalise :: Path ar fd -> Path ar fd -- | Deconstructs a path into its components. -- --
--   > splitPath (asAbsDir "/tmp/someDir/mydir.dir") == (["tmp","someDir","mydir.dir"], Nothing)
--   > splitPath (asAbsFile "/tmp/someDir/myfile.txt") == (["tmp","someDir"], Just "myfile.txt")
--   
splitPath :: FileDirClass fd => Path ar fd -> ([RelDir], Maybe RelFile) -- | This function can be used to construct a relative path by removing the -- supplied AbsDir from the front. It is a runtime error if -- the supplied AbsPath doesn't start with the AbsDir. -- --
--   > makeRelative "/tmp/somedir" "/tmp/somedir/anotherdir/file.txt" == asRelFile "anotherdir/file.txt"
--   > makeRelative "/tmp/somedir" "/tmp/somedir/anotherdir/dir" == asRelDir "anotherdir/dir"
--   
makeRelative :: AbsDir -> AbsPath fd -> RelPath fd -- | Joins an absolute directory with a relative path to construct a new -- absolute path. -- --
--   > makeAbsolute "/tmp" "file.txt"      == asAbsFile "/tmp/file.txt"
--   > makeAbsolute "/tmp" "adir/file.txt" == asAbsFile "/tmp/adir/file.txt"
--   > makeAbsolute "/tmp" "adir/dir"      == asAbsDir "/tmp/adir/dir"
--   
makeAbsolute :: AbsDir -> RelPath fd -> AbsPath fd -- | Converts a relative path into an absolute one by prepending the -- current working directory. makeAbsoluteFromCwd :: RelPath fd -> IO (AbsPath fd) -- | As for makeAbsolute, but for use when the path may already be -- absolute (in which case it is left unchanged). -- --
--   > genericMakeAbsolute "/tmp" (asRelFile "file.txt")       == "/tmp/file.txt"
--   > genericMakeAbsolute "/tmp" (asRelFile "adir/file.txt")  == "/tmp/adir/file.txt"
--   > genericMakeAbsolute "/tmp" (asAbsFile "adir/file.txt")  == "/adir/file.txt"
--   > genericMakeAbsolute "/tmp" (asAbsFile "/adir/file.txt") == "/adir/file.txt"
--   
genericMakeAbsolute :: AbsRelClass ar => AbsDir -> Path ar fd -> AbsPath fd -- | As for makeAbsoluteFromCwd, but for use when the path may -- already be absolute (in which case it is left unchanged). genericMakeAbsoluteFromCwd :: AbsRelClass ar => Path ar fd -> IO (AbsPath fd) -- | Map over the components of the path. -- --
--   > pathMap (map toLower) "/tmp/Reports/SpreadSheets" == "/tmp/reports/spreadsheets"
--   
pathMap :: (String -> String) -> Path ar fd -> Path ar fd -- | Test whether a Path ar fd is absolute. -- --
--   > isAbsolute (asAbsFile "fred")  == True
--   > isAbsolute (asRelFile "fred")  == False
--   > isAbsolute (asAbsFile "/fred") == True
--   > isAbsolute (asRelFile "/fred") == False
--   
isAbsolute :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to an absolute path if -- interpreted as a Path. isAbsoluteString :: String -> Bool -- | Invariant - this should return True iff arg is of type Path -- Rel _ -- --
--   isRelative = not . isAbsolute
--   
isRelative :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to a relative path if -- interpreted as a Path. -- --
--   isRelativeString = not . isAbsoluteString
--   
isRelativeString :: String -> Bool -- | Does the given filename have an extension? -- --
--   > null (takeExtension x) == not (hasAnExtension x)
--   
hasAnExtension :: FilePath ar -> Bool -- | Does the given filename have the given extension? -- --
--   > hasExtension ".hs" "MyCode.hs" == True
--   > hasExtension ".hs" "MyCode.hs.bak" == False
--   > hasExtension ".hs" "MyCode.bak.hs" == True
--   
hasExtension :: String -> FilePath ar -> Bool -- | This is largely for FilePath compatability addTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatability dropTrailingPathSeparator :: String -> String -- | File extension character -- --
--   > extSeparator == '.'
--   
extSeparator :: Char -- | This is largely for FilePath compatability hasTrailingPathSeparator :: String -> Bool -- | The character that separates directories. In the case where more than -- one character is possible, pathSeparator is the 'ideal' one. -- --
--   > isPathSeparator pathSeparator
--   
pathSeparator :: Char -- | The list of all possible separators. -- --
--   > pathSeparator `elem` pathSeparators
--   
pathSeparators :: [Char] -- | The character that is used to separate the entries in the $PATH -- environment variable. searchPathSeparator :: Char -- | Is the character an extension character? -- --
--   > isExtSeparator a == (a == extSeparator)
--   
isExtSeparator :: Char -> Bool -- | Rather than using (== pathSeparator), use this. Test -- if something is a path separator. -- --
--   > isPathSeparator a == (a `elem` pathSeparators)
--   
isPathSeparator :: Char -> Bool -- | Is the character a file separator? -- --
--   > isSearchPathSeparator a == (a == searchPathSeparator)
--   
isSearchPathSeparator :: Char -> Bool -- | This is a more flexible variant of addExtension / -- <.> which can work with files or directories -- --
--   > genericAddExtension "/" "x" == asAbsDir "/.x"
--   > genericAddExtension "/a" "x" == asAbsDir "/a.x"
--   > genericAddExtension "" "x" == asRelFile ".x"
--   > genericAddExtension "" "" == asRelFile ""
--   
genericAddExtension :: Path ar fd -> String -> Path ar fd genericDropExtension :: Path ar fd -> Path ar fd genericDropExtensions :: Path ar fd -> Path ar fd genericSplitExtension :: Path ar fd -> (Path ar fd, String) genericSplitExtensions :: Path ar fd -> (Path ar fd, String) genericTakeExtension :: Path ar fd -> String genericTakeExtensions :: Path ar fd -> String instance GHC.Classes.Ord (System.Path.Windows.Path ar fd) instance GHC.Classes.Eq (System.Path.Windows.Path ar fd) instance GHC.Classes.Ord System.Path.Windows.PathComponent instance GHC.Classes.Eq System.Path.Windows.PathComponent instance Control.DeepSeq.NFData System.Path.Windows.PathComponent instance Control.DeepSeq.NFData (System.Path.Windows.Path ar fd) instance System.Path.Windows.Private System.Path.Windows.Abs instance System.Path.Windows.Private System.Path.Windows.Rel instance System.Path.Windows.Private System.Path.Windows.File instance System.Path.Windows.Private System.Path.Windows.Dir instance System.Path.Windows.AbsRelClass System.Path.Windows.Abs instance System.Path.Windows.AbsRelClass System.Path.Windows.Rel instance System.Path.Windows.FileDirClass System.Path.Windows.File instance System.Path.Windows.FileDirClass System.Path.Windows.Dir instance System.Path.Windows.AbsRelClass ar => GHC.Show.Show (System.Path.Windows.Path ar fd) instance System.Path.Windows.AbsRelClass ar => GHC.Read.Read (System.Path.Windows.Path ar fd) instance Data.String.IsString (System.Path.Windows.Path ar fd) instance Test.QuickCheck.Arbitrary.Arbitrary System.Path.Windows.PathComponent instance (System.Path.Windows.AbsRelClass ar, System.Path.Windows.FileDirClass fd) => Test.QuickCheck.Arbitrary.Arbitrary (System.Path.Windows.Path ar fd) -- | This module provides type-safe access to filepath manipulations. -- -- Normally you would import Path (which will use the default -- implementation for the host platform) instead of this. However, -- importing this explicitly allows for manipulation of non-native paths. module System.Path.Posix -- | This is the main filepath abstract datatype data Path ar fd data Abs data Rel data File data Dir 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 -- | This class allows selective behaviour for absolute and relative paths -- and is mostly for internal use. class Private ar => AbsRelClass ar where absRel f g = runAbsRel $ switchAbsRel (AbsRel f) (AbsRel g) -- | See https://wiki.haskell.org/Closed_world_instances for the -- used technique. switchAbsRel :: AbsRelClass ar => f Abs -> f Rel -> f ar -- | Will become a top-level function in future absRel :: AbsRelClass ar => (AbsPath fd -> a) -> (RelPath fd -> a) -> Path ar fd -> a -- | This class allows selective behaviour for file and directory paths and -- is mostly for internal use. class Private fd => FileDirClass fd where fileDir f g = runFileDir $ switchFileDir (FileDirFunc f) (FileDirFunc g) switchFileDir :: FileDirClass fd => f File -> f Dir -> f fd -- | Will become a top-level function in future fileDir :: FileDirClass fd => (FilePath ar -> a) -> (DirPath ar -> a) -> Path ar fd -> a -- | Convert the Path into a plain String as required for OS -- calls. getPathString :: AbsRelClass ar => Path ar fd -> String rootDir :: AbsDir currentDir :: RelDir -- | Use a String as a Path whose type is determined by its -- context. -- --
--   > asPath "/tmp" == "/tmp"
--   > asPath "file.txt" == "file.txt"
--   > isAbsolute (asPath "/tmp" :: AbsDir) == True
--   > isAbsolute (asPath "/tmp" :: RelDir) == False
--   > getPathString (asPath "/tmp" :: AbsDir) == "/tmp"
--   > getPathString (asPath "/tmp" :: RelDir) == "tmp"
--   
asPath :: String -> Path ar fd -- | Use a String as a RelFile. No checking is done. -- --
--   > getPathString (asRelFile "file.txt") == "file.txt"
--   > getPathString (asRelFile "/file.txt") == "file.txt"
--   > getPathString (asRelFile "tmp") == "tmp"
--   > getPathString (asRelFile "/tmp") == "tmp"
--   
asRelFile :: String -> RelFile -- | Use a String as a RelDir. No checking is done. -- --
--   > getPathString (asRelDir ".") == "."
--   > getPathString (asRelDir "file.txt") == "file.txt"
--   > getPathString (asRelDir "/file.txt") == "file.txt"
--   > getPathString (asRelDir "tmp") == "tmp"
--   > getPathString (asRelDir "/tmp") == "tmp"
--   
asRelDir :: String -> RelDir -- | Use a String as an AbsFile. No checking is done. -- --
--   > getPathString (asAbsFile "file.txt") == "/file.txt"
--   > getPathString (asAbsFile "/file.txt") == "/file.txt"
--   > getPathString (asAbsFile "tmp") == "/tmp"
--   > getPathString (asAbsFile "/tmp") == "/tmp"
--   
asAbsFile :: String -> AbsFile -- | Use a String as an AbsDir. No checking is done. -- --
--   > getPathString (asAbsDir "file.txt") == "/file.txt"
--   > getPathString (asAbsDir "/file.txt") == "/file.txt"
--   > getPathString (asAbsDir "tmp") == "/tmp"
--   > getPathString (asAbsDir "/tmp") == "/tmp"
--   
asAbsDir :: String -> AbsDir -- | Use a String as a 'RelPath fd'. No checking is done. asRelPath :: String -> RelPath fd -- | Use a String as an 'AbsPath fd'. No checking is done. asAbsPath :: String -> AbsPath fd -- | Use a String as a 'FilePath ar'. No checking is done. asFilePath :: String -> FilePath ar -- | Use a String as a 'DirPath ar'. No checking is done. asDirPath :: String -> DirPath ar -- | Examines the supplied string and constructs an absolute or relative -- path as appropriate. -- --
--   > mkPathAbsOrRel "/tmp" == Left (asAbsDir "/tmp")
--   > mkPathAbsOrRel  "tmp" == Right (asRelDir "tmp")
--   
mkPathAbsOrRel :: String -> Either (AbsPath fd) (RelPath fd) -- | Searches for a file or directory with the supplied path string and -- returns a File or Dir path as appropriate. If neither -- exists at the supplied path, Nothing is returned. mkPathFileOrDir :: AbsRelClass ar => String -> IO (Maybe (Either (FilePath ar) (DirPath ar))) -- | Convert a String into an AbsPath by interpreting it as -- relative to the supplied directory if necessary. -- --
--   > mkAbsPath "/tmp" "foo.txt" == "/tmp/foo.txt"
--   > mkAbsPath "/tmp" "/etc/foo.txt" == "/etc/foo.txt"
--   
mkAbsPath :: AbsDir -> String -> AbsPath fd -- | Convert a String into an AbsPath by interpreting it as -- relative to the cwd if necessary. mkAbsPathFromCwd :: String -> IO (AbsPath fd) -- | Infix variant of combine. () :: DirPath ar -> RelPath fd -> Path ar fd -- | Infix variant of addExtension. We only allow files (and not -- directories) to have extensions added by this function. This is -- because it's the vastly common case and an attempt to add one to a -- directory will - more often than not - represent an error. We don't -- however want to prevent the corresponding operation on directories, -- and so we provide a function that is more flexible: -- genericAddExtension. (<.>) :: FilePath ar -> String -> FilePath ar -- | Add an extension, even if there is already one there. E.g. -- addExtension "foo.txt" "bat" -> "foo.txt.bat". -- --
--   > addExtension "file.txt" "bib" == "file.txt.bib"
--   > addExtension "file." ".bib" == "file..bib"
--   > addExtension "file" ".bib" == "file.bib"
--   > addExtension "" "bib" == ".bib"
--   > addExtension "" ".bib" == ".bib"
--   > takeFileName (addExtension "" "ext") == ".ext"
--   
addExtension :: FilePath ar -> String -> FilePath ar -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. combine :: DirPath ar -> RelPath fd -> Path ar fd -- | Remove last extension, and the "." preceding it. -- --
--   > dropExtension x == fst (splitExtension x)
--   
dropExtension :: FilePath ar -> FilePath ar -- | Drop all extensions -- --
--   > not $ hasAnExtension (dropExtensions x)
--   
dropExtensions :: FilePath ar -> FilePath ar -- | Synonym for takeDirectory dropFileName :: Path ar fd -> DirPath ar -- | Set the extension of a file, overwriting one if already present. -- --
--   > replaceExtension "file.txt" ".bob" == "file.bob"
--   > replaceExtension "file.txt" "bob" == "file.bob"
--   > replaceExtension "file" ".bob" == "file.bob"
--   > replaceExtension "file.txt" "" == "file"
--   > replaceExtension "file.fred.bob" "txt" == "file.fred.txt"
--   
replaceExtension :: FilePath ar -> String -> FilePath ar replaceBaseName :: Path ar fd -> String -> Path ar fd replaceDirectory :: Path ar1 fd -> DirPath ar2 -> Path ar2 fd replaceFileName :: Path ar fd -> String -> Path ar fd -- | Split on the extension. addExtension is the inverse. -- --
--   > uncurry (<.>) (splitExtension x) == x
--   > uncurry addExtension (splitExtension x) == x
--   > splitExtension "file.txt" == ("file",".txt")
--   > splitExtension "file" == ("file","")
--   > splitExtension "file/file.txt" == ("file/file",".txt")
--   > splitExtension "file.txt/boris" == ("file.txt/boris","")
--   > splitExtension "file.txt/boris.ext" == ("file.txt/boris",".ext")
--   > splitExtension "file/path.txt.bob.fred" == ("file/path.txt.bob",".fred")
--   
splitExtension :: FilePath ar -> (FilePath ar, String) -- | Split on all extensions -- --
--   > splitExtensions "file.tar.gz" == ("file",".tar.gz")
--   
splitExtensions :: FilePath ar -> (FilePath ar, String) -- | Path must not be empty splitFileName :: Path ar fd -> (DirPath ar, RelPath fd) -- | Get the basename of a file -- --
--   > takeBaseName "/tmp/somedir/myfile.txt" == "myfile"
--   > takeBaseName "./myfile.txt" == "myfile"
--   > takeBaseName "myfile.txt" == "myfile"
--   
takeBaseName :: Path ar fd -> RelPath fd takeDirectory :: Path ar fd -> DirPath ar -- | Get the extension of a file, returns "" for no extension, -- .ext otherwise. -- --
--   > takeExtension x == snd (splitExtension x)
--   > takeExtension (addExtension x "ext") == ".ext"
--   > takeExtension (replaceExtension x "ext") == ".ext"
--   
takeExtension :: FilePath ar -> String -- | Get all extensions -- --
--   > takeExtensions "file.tar.gz" == ".tar.gz"
--   
takeExtensions :: FilePath ar -> String -- | Get the filename component of a file path (ie stripping all parent -- dirs) -- --
--   > takeFileName "/tmp/somedir/myfile.txt" == "myfile.txt"
--   > takeFileName "./myfile.txt" == "myfile.txt"
--   > takeFileName "myfile.txt" == "myfile.txt"
--   
takeFileName :: Path ar fd -> RelPath fd -- | Check whether two strings are equal as file paths. -- --
--   > equalFilePath "/tmp/" "/tmp" == True
--   > equalFilePath "/tmp"  "tmp"  == False
--   
equalFilePath :: String -> String -> Bool -- | Constructs a Path from a list of components. -- --
--   > joinPath ["/tmp","someDir","file.txt"] == "/tmp/someDir/file.txt"
--   > joinPath ["/tmp","someDir","file.txt"] == asRelFile "tmp/someDir/file.txt"
--   
joinPath :: [String] -> Path ar fd -- | Currently just transforms: -- --
--   > normalise "/tmp/fred/./jim/./file" == "/tmp/fred/jim/file"
--   
normalise :: Path ar fd -> Path ar fd -- | Deconstructs a path into its components. -- --
--   > splitPath (asAbsDir "/tmp/someDir/mydir.dir") == (["tmp","someDir","mydir.dir"], Nothing)
--   > splitPath (asAbsFile "/tmp/someDir/myfile.txt") == (["tmp","someDir"], Just "myfile.txt")
--   
splitPath :: FileDirClass fd => Path ar fd -> ([RelDir], Maybe RelFile) -- | This function can be used to construct a relative path by removing the -- supplied AbsDir from the front. It is a runtime error if -- the supplied AbsPath doesn't start with the AbsDir. -- --
--   > makeRelative "/tmp/somedir" "/tmp/somedir/anotherdir/file.txt" == asRelFile "anotherdir/file.txt"
--   > makeRelative "/tmp/somedir" "/tmp/somedir/anotherdir/dir" == asRelDir "anotherdir/dir"
--   
makeRelative :: AbsDir -> AbsPath fd -> RelPath fd -- | Joins an absolute directory with a relative path to construct a new -- absolute path. -- --
--   > makeAbsolute "/tmp" "file.txt"      == asAbsFile "/tmp/file.txt"
--   > makeAbsolute "/tmp" "adir/file.txt" == asAbsFile "/tmp/adir/file.txt"
--   > makeAbsolute "/tmp" "adir/dir"      == asAbsDir "/tmp/adir/dir"
--   
makeAbsolute :: AbsDir -> RelPath fd -> AbsPath fd -- | Converts a relative path into an absolute one by prepending the -- current working directory. makeAbsoluteFromCwd :: RelPath fd -> IO (AbsPath fd) -- | As for makeAbsolute, but for use when the path may already be -- absolute (in which case it is left unchanged). -- --
--   > genericMakeAbsolute "/tmp" (asRelFile "file.txt")       == "/tmp/file.txt"
--   > genericMakeAbsolute "/tmp" (asRelFile "adir/file.txt")  == "/tmp/adir/file.txt"
--   > genericMakeAbsolute "/tmp" (asAbsFile "adir/file.txt")  == "/adir/file.txt"
--   > genericMakeAbsolute "/tmp" (asAbsFile "/adir/file.txt") == "/adir/file.txt"
--   
genericMakeAbsolute :: AbsRelClass ar => AbsDir -> Path ar fd -> AbsPath fd -- | As for makeAbsoluteFromCwd, but for use when the path may -- already be absolute (in which case it is left unchanged). genericMakeAbsoluteFromCwd :: AbsRelClass ar => Path ar fd -> IO (AbsPath fd) -- | Map over the components of the path. -- --
--   > pathMap (map toLower) "/tmp/Reports/SpreadSheets" == "/tmp/reports/spreadsheets"
--   
pathMap :: (String -> String) -> Path ar fd -> Path ar fd -- | Test whether a Path ar fd is absolute. -- --
--   > isAbsolute (asAbsFile "fred")  == True
--   > isAbsolute (asRelFile "fred")  == False
--   > isAbsolute (asAbsFile "/fred") == True
--   > isAbsolute (asRelFile "/fred") == False
--   
isAbsolute :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to an absolute path if -- interpreted as a Path. isAbsoluteString :: String -> Bool -- | Invariant - this should return True iff arg is of type Path -- Rel _ -- --
--   isRelative = not . isAbsolute
--   
isRelative :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to a relative path if -- interpreted as a Path. -- --
--   isRelativeString = not . isAbsoluteString
--   
isRelativeString :: String -> Bool -- | Does the given filename have an extension? -- --
--   > null (takeExtension x) == not (hasAnExtension x)
--   
hasAnExtension :: FilePath ar -> Bool -- | Does the given filename have the given extension? -- --
--   > hasExtension ".hs" "MyCode.hs" == True
--   > hasExtension ".hs" "MyCode.hs.bak" == False
--   > hasExtension ".hs" "MyCode.bak.hs" == True
--   
hasExtension :: String -> FilePath ar -> Bool -- | This is largely for FilePath compatability addTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatability dropTrailingPathSeparator :: String -> String -- | File extension character -- --
--   > extSeparator == '.'
--   
extSeparator :: Char -- | This is largely for FilePath compatability hasTrailingPathSeparator :: String -> Bool -- | The character that separates directories. In the case where more than -- one character is possible, pathSeparator is the 'ideal' one. -- --
--   > isPathSeparator pathSeparator
--   
pathSeparator :: Char -- | The list of all possible separators. -- --
--   > pathSeparator `elem` pathSeparators
--   
pathSeparators :: [Char] -- | The character that is used to separate the entries in the $PATH -- environment variable. searchPathSeparator :: Char -- | Is the character an extension character? -- --
--   > isExtSeparator a == (a == extSeparator)
--   
isExtSeparator :: Char -> Bool -- | Rather than using (== pathSeparator), use this. Test -- if something is a path separator. -- --
--   > isPathSeparator a == (a `elem` pathSeparators)
--   
isPathSeparator :: Char -> Bool -- | Is the character a file separator? -- --
--   > isSearchPathSeparator a == (a == searchPathSeparator)
--   
isSearchPathSeparator :: Char -> Bool -- | This is a more flexible variant of addExtension / -- <.> which can work with files or directories -- --
--   > genericAddExtension "/" "x" == asAbsDir "/.x"
--   > genericAddExtension "/a" "x" == asAbsDir "/a.x"
--   > genericAddExtension "" "x" == asRelFile ".x"
--   > genericAddExtension "" "" == asRelFile ""
--   
genericAddExtension :: Path ar fd -> String -> Path ar fd genericDropExtension :: Path ar fd -> Path ar fd genericDropExtensions :: Path ar fd -> Path ar fd genericSplitExtension :: Path ar fd -> (Path ar fd, String) genericSplitExtensions :: Path ar fd -> (Path ar fd, String) genericTakeExtension :: Path ar fd -> String genericTakeExtensions :: Path ar fd -> String instance GHC.Classes.Ord (System.Path.Posix.Path ar fd) instance GHC.Classes.Eq (System.Path.Posix.Path ar fd) instance GHC.Classes.Ord System.Path.Posix.PathComponent instance GHC.Classes.Eq System.Path.Posix.PathComponent instance Control.DeepSeq.NFData System.Path.Posix.PathComponent instance Control.DeepSeq.NFData (System.Path.Posix.Path ar fd) instance System.Path.Posix.Private System.Path.Posix.Abs instance System.Path.Posix.Private System.Path.Posix.Rel instance System.Path.Posix.Private System.Path.Posix.File instance System.Path.Posix.Private System.Path.Posix.Dir instance System.Path.Posix.AbsRelClass System.Path.Posix.Abs instance System.Path.Posix.AbsRelClass System.Path.Posix.Rel instance System.Path.Posix.FileDirClass System.Path.Posix.File instance System.Path.Posix.FileDirClass System.Path.Posix.Dir instance System.Path.Posix.AbsRelClass ar => GHC.Show.Show (System.Path.Posix.Path ar fd) instance System.Path.Posix.AbsRelClass ar => GHC.Read.Read (System.Path.Posix.Path ar fd) instance Data.String.IsString (System.Path.Posix.Path ar fd) instance Test.QuickCheck.Arbitrary.Arbitrary System.Path.Posix.PathComponent instance (System.Path.Posix.AbsRelClass ar, System.Path.Posix.FileDirClass fd) => Test.QuickCheck.Arbitrary.Arbitrary (System.Path.Posix.Path ar fd) -- | 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 module System.Path -- | This module provides type-safe access to directory manipulations. -- -- It is designed to be imported instead of System.Directory. (It -- is intended to provide versions of functions from that module which -- have equivalent functionality but are more typesafe). -- System.Path is a companion module providing a type-safe -- alternative to System.FilePath. -- -- You will typically want to import as follows: -- --
--   import Prelude hiding (FilePath)
--   import System.Path
--   import System.Path.Directory
--   import System.Path.IO
--   
-- -- Ben Moseley - (c) 2009 module System.Path.Directory createDirectory :: AbsRelClass ar => DirPath ar -> IO () createDirectoryIfMissing :: AbsRelClass ar => Bool -> DirPath ar -> IO () removeDirectory :: AbsRelClass ar => DirPath ar -> IO () removeDirectoryRecursive :: AbsRelClass ar => DirPath ar -> IO () renameDirectory :: (AbsRelClass ar1, AbsRelClass ar2) => DirPath ar1 -> DirPath ar2 -> IO () -- | An alias for relDirectoryContents. getDirectoryContents :: AbsRelClass ar => DirPath ar -> IO ([RelDir], [RelFile]) -- | Retrieve the contents of a directory path (which may be relative) as -- absolute paths absDirectoryContents :: AbsRelClass ar => DirPath ar -> IO ([AbsDir], [AbsFile]) -- | Returns paths relative to the supplied (abs or relative) -- directory path. eg (for current working directory of -- /somewhere/cwd/): -- --
--   show (relDirectoryContents "d/e/f/") == (["subDir1A","subDir1B"],
--                                                        ["file1A","file1B"])
--   
relDirectoryContents :: AbsRelClass ar => DirPath ar -> IO ([RelDir], [RelFile]) -- | A convenient alternative to relDirectoryContents if you only -- want files. filesInDir :: AbsRelClass ar => DirPath ar -> IO [RelFile] -- | A convenient alternative to relDirectoryContents if you only -- want directories. dirsInDir :: AbsRelClass ar => DirPath ar -> IO [RelDir] getCurrentDirectory :: IO AbsDir setCurrentDirectory :: AbsRelClass ar => DirPath ar -> IO () getHomeDirectory :: IO AbsDir getAppUserDataDirectory :: String -> IO AbsDir getUserDocumentsDirectory :: IO AbsDir getTemporaryDirectory :: IO AbsDir removeFile :: AbsRelClass ar => FilePath ar -> IO () renameFile :: (AbsRelClass ar1, AbsRelClass ar2) => FilePath ar1 -> FilePath ar2 -> IO () copyFile :: (AbsRelClass ar1, AbsRelClass ar2) => FilePath ar1 -> FilePath ar2 -> IO () canonicalizePath :: AbsRelClass ar => Path ar fd -> IO (AbsPath fd) makeRelativeToCurrentDirectory :: AbsRelClass ar => Path ar fd -> IO (RelPath fd) findExecutable :: String -> IO (Maybe AbsFile) doesFileExist :: AbsRelClass ar => FilePath ar -> IO Bool doesDirectoryExist :: AbsRelClass ar => DirPath ar -> IO Bool data Permissions :: * getPermissions :: AbsRelClass ar => Path ar fd -> IO Permissions setPermissions :: AbsRelClass ar => Path ar fd -> Permissions -> IO () getModificationTime :: AbsRelClass ar => Path ar fd -> IO UTCTime -- | This module provides type-safe access to IO operations. -- -- It is designed to be imported instead of System.IO. (It is -- intended to provide versions of functions from that module which have -- equivalent functionality but are more typesafe). System.Path is -- a companion module providing a type-safe alternative to -- System.FilePath. -- -- You will typically want to import as follows: -- --
--   import Prelude hiding (FilePath)
--   import System.Path
--   import System.Path.Directory
--   import System.Path.IO
--   
-- -- Ben Moseley - (c) 2009 module System.Path.IO withFile :: AbsRelClass ar => FilePath ar -> IOMode -> (Handle -> IO r) -> IO r openFile :: AbsRelClass ar => FilePath ar -> IOMode -> IO Handle readFile :: AbsRelClass ar => FilePath ar -> IO String writeFile :: AbsRelClass ar => FilePath ar -> String -> IO () appendFile :: AbsRelClass ar => FilePath ar -> String -> IO () withBinaryFile :: AbsRelClass ar => FilePath ar -> IOMode -> (Handle -> IO r) -> IO r openBinaryFile :: AbsRelClass ar => FilePath ar -> IOMode -> IO Handle openTempFile :: AbsRelClass ar => DirPath ar -> RelFile -> IO (AbsFile, Handle) openBinaryTempFile :: AbsRelClass ar => DirPath ar -> RelFile -> IO (AbsFile, Handle) -- | A value of type IO a is a computation which, when -- performed, does some I/O before returning a value of type a. -- -- There is really only one way to "perform" an I/O action: bind it to -- Main.main in your program. When your program is run, the I/O -- will be performed. It isn't possible to perform I/O from an arbitrary -- function, unless that function is itself in the IO monad and -- called at some point, directly or indirectly, from Main.main. -- -- IO is a monad, so IO actions can be combined using -- either the do-notation or the >> and >>= -- operations from the Monad class. data IO a :: * -> * fixIO :: (a -> IO a) -> IO a -- | Haskell defines operations to read and write characters from and to -- files, represented by values of type Handle. Each value of -- this type is a handle: a record used by the Haskell run-time -- system to manage I/O with file system objects. A handle has at -- least the following properties: -- -- -- -- Most handles will also have a current I/O position indicating where -- the next input or output operation will occur. A handle is -- readable if it manages only input or both input and output; -- likewise, it is writable if it manages only output or both -- input and output. A handle is open when first allocated. Once -- it is closed it can no longer be used for either input or output, -- though an implementation cannot re-use its storage while references -- remain to it. Handles are in the Show and Eq classes. -- The string produced by showing a handle is system dependent; it should -- include enough information to identify the handle for debugging. A -- handle is equal according to == only to itself; no attempt is -- made to compare the internal state of different handles for equality. data Handle :: * -- | A handle managing input from the Haskell program's standard input -- channel. stdin :: Handle -- | A handle managing output to the Haskell program's standard output -- channel. stdout :: Handle -- | A handle managing output to the Haskell program's standard error -- channel. stderr :: Handle -- | See openFile data IOMode :: * ReadMode :: IOMode WriteMode :: IOMode AppendMode :: IOMode ReadWriteMode :: IOMode -- | Computation hClose hdl makes handle hdl -- closed. Before the computation finishes, if hdl is writable -- its buffer is flushed as for hFlush. Performing hClose -- on a handle that has already been closed has no effect; doing so is -- not an error. All other operations on a closed handle will fail. If -- hClose fails for any reason, any further operations (apart from -- hClose) on the handle will still fail as if hdl had -- been successfully closed. hClose :: Handle -> IO () -- | For a handle hdl which attached to a physical file, -- hFileSize hdl returns the size of that file in 8-bit -- bytes. hFileSize :: Handle -> IO Integer -- | hSetFileSize hdl size truncates the physical -- file with handle hdl to size bytes. hSetFileSize :: Handle -> Integer -> IO () -- | For a readable handle hdl, hIsEOF hdl returns -- True if no further input can be taken from hdl or for -- a physical file, if the current I/O position is equal to the length of -- the file. Otherwise, it returns False. -- -- NOTE: hIsEOF may block, because it has to attempt to read from -- the stream to determine whether there is any more data to be read. hIsEOF :: Handle -> IO Bool -- | The computation isEOF is identical to hIsEOF, except -- that it works only on stdin. isEOF :: IO Bool -- | Three kinds of buffering are supported: line-buffering, -- block-buffering or no-buffering. These modes have the following -- effects. For output, items are written out, or flushed, from -- the internal buffer according to the buffer mode: -- -- -- -- An implementation is free to flush the buffer more frequently, but not -- less frequently, than specified above. The output buffer is emptied as -- soon as it has been written out. -- -- Similarly, input occurs according to the buffer mode for the handle: -- -- -- -- The default buffering mode when a handle is opened is -- implementation-dependent and may depend on the file system object -- which is attached to that handle. For most implementations, physical -- files will normally be block-buffered and terminals will normally be -- line-buffered. data BufferMode :: * -- | buffering is disabled if possible. NoBuffering :: BufferMode -- | line-buffering should be enabled if possible. LineBuffering :: BufferMode -- | block-buffering should be enabled if possible. The size of the buffer -- is n items if the argument is Just n and is -- otherwise implementation-dependent. BlockBuffering :: Maybe Int -> BufferMode -- | Computation hSetBuffering hdl mode sets the mode of -- buffering for handle hdl on subsequent reads and writes. -- -- If the buffer mode is changed from BlockBuffering or -- LineBuffering to NoBuffering, then -- -- -- -- This operation may fail with: -- -- hSetBuffering :: Handle -> BufferMode -> IO () -- | Computation hGetBuffering hdl returns the current -- buffering mode for hdl. hGetBuffering :: Handle -> IO BufferMode -- | The action hFlush hdl causes any items buffered for -- output in handle hdl to be sent immediately to the operating -- system. -- -- This operation may fail with: -- -- hFlush :: Handle -> IO () -- | Computation hGetPosn hdl returns the current I/O -- position of hdl as a value of the abstract type -- HandlePosn. hGetPosn :: Handle -> IO HandlePosn -- | If a call to hGetPosn hdl returns a position -- p, then computation hSetPosn p sets the -- position of hdl to the position it held at the time of the -- call to hGetPosn. -- -- This operation may fail with: -- -- hSetPosn :: HandlePosn -> IO () data HandlePosn :: * -- | Computation hSeek hdl mode i sets the position of -- handle hdl depending on mode. The offset i -- is given in terms of 8-bit bytes. -- -- If hdl is block- or line-buffered, then seeking to a position -- which is not in the current buffer will first cause any items in the -- output buffer to be written to the device, and then cause the input -- buffer to be discarded. Some handles may not be seekable (see -- hIsSeekable), or only support a subset of the possible -- positioning operations (for instance, it may only be possible to seek -- to the end of a tape, or to a positive offset from the beginning or -- current position). It is not possible to set a negative I/O position, -- or for a physical file, an I/O position beyond the current -- end-of-file. -- -- This operation may fail with: -- -- hSeek :: Handle -> SeekMode -> Integer -> IO () -- | A mode that determines the effect of hSeek hdl mode -- i. data SeekMode :: * -- | the position of hdl is set to i. AbsoluteSeek :: SeekMode -- | the position of hdl is set to offset i from the -- current position. RelativeSeek :: SeekMode -- | the position of hdl is set to offset i from the end -- of the file. SeekFromEnd :: SeekMode -- | Computation hTell hdl returns the current position of -- the handle hdl, as the number of bytes from the beginning of -- the file. The value returned may be subsequently passed to -- hSeek to reposition the handle to the current position. -- -- This operation may fail with: -- -- hTell :: Handle -> IO Integer hIsOpen :: Handle -> IO Bool hIsClosed :: Handle -> IO Bool hIsReadable :: Handle -> IO Bool hIsWritable :: Handle -> IO Bool hIsSeekable :: Handle -> IO Bool -- | Is the handle connected to a terminal? hIsTerminalDevice :: Handle -> IO Bool -- | Set the echoing status of a handle connected to a terminal. hSetEcho :: Handle -> Bool -> IO () -- | Get the echoing status of a handle connected to a terminal. hGetEcho :: Handle -> IO Bool -- | hShow is in the IO monad, and gives more comprehensive -- output than the (pure) instance of Show for Handle. hShow :: Handle -> IO String -- | Computation hWaitForInput hdl t waits until input is -- available on handle hdl. It returns True as soon as -- input is available on hdl, or False if no input is -- available within t milliseconds. Note that -- hWaitForInput waits until one or more full characters -- are available, which means that it needs to do decoding, and hence may -- fail with a decoding error. -- -- If t is less than zero, then hWaitForInput waits -- indefinitely. -- -- This operation may fail with: -- -- -- -- NOTE for GHC users: unless you use the -threaded flag, -- hWaitForInput hdl t where t >= 0 will block all -- other Haskell threads for the duration of the call. It behaves like a -- safe foreign call in this respect. hWaitForInput :: Handle -> Int -> IO Bool -- | Computation hReady hdl indicates whether at least one -- item is available for input from handle hdl. -- -- This operation may fail with: -- -- hReady :: Handle -> IO Bool -- | Computation hGetChar hdl reads a character from the -- file or channel managed by hdl, blocking until a character is -- available. -- -- This operation may fail with: -- -- hGetChar :: Handle -> IO Char -- | Computation hGetLine hdl reads a line from the file or -- channel managed by hdl. -- -- This operation may fail with: -- -- -- -- If hGetLine encounters end-of-file at any other point while -- reading in a line, it is treated as a line terminator and the -- (partial) line is returned. hGetLine :: Handle -> IO String -- | Computation hLookAhead returns the next character from the -- handle without removing it from the input buffer, blocking until a -- character is available. -- -- This operation may fail with: -- -- hLookAhead :: Handle -> IO Char -- | Computation hGetContents hdl returns the list of -- characters corresponding to the unread portion of the channel or file -- managed by hdl, which is put into an intermediate state, -- semi-closed. In this state, hdl is effectively closed, -- but items are read from hdl on demand and accumulated in a -- special list returned by hGetContents hdl. -- -- Any operation that fails because a handle is closed, also fails if a -- handle is semi-closed. The only exception is hClose. A -- semi-closed handle becomes closed: -- -- -- -- Once a semi-closed handle becomes closed, the contents of the -- associated list becomes fixed. The contents of this final list is only -- partially specified: it will contain at least all the items of the -- stream that were evaluated prior to the handle becoming closed. -- -- Any I/O errors encountered while a handle is semi-closed are simply -- discarded. -- -- This operation may fail with: -- -- hGetContents :: Handle -> IO String -- | Computation hPutChar hdl ch writes the character -- ch to the file or channel managed by hdl. Characters -- may be buffered if buffering is enabled for hdl. -- -- This operation may fail with: -- -- hPutChar :: Handle -> Char -> IO () -- | Computation hPutStr hdl s writes the string s -- to the file or channel managed by hdl. -- -- This operation may fail with: -- -- hPutStr :: Handle -> String -> IO () -- | The same as hPutStr, but adds a newline character. hPutStrLn :: Handle -> String -> IO () -- | Computation hPrint hdl t writes the string -- representation of t given by the shows function to the -- file or channel managed by hdl and appends a newline. -- -- This operation may fail with: -- -- hPrint :: Show a => Handle -> a -> IO () -- | The interact function takes a function of type -- String->String as its argument. The entire input from the -- standard input device is passed to this function as its argument, and -- the resulting string is output on the standard output device. interact :: (String -> String) -> IO () -- | Write a character to the standard output device (same as -- hPutChar stdout). putChar :: Char -> IO () -- | Write a string to the standard output device (same as hPutStr -- stdout). putStr :: String -> IO () -- | The same as putStr, but adds a newline character. putStrLn :: String -> IO () -- | The print function outputs a value of any printable type to the -- standard output device. Printable types are those that are instances -- of class Show; print converts values to strings for -- output using the show operation and adds a newline. -- -- For example, a program to print the first 20 integers and their powers -- of 2 could be written as: -- --
--   main = print ([(n, 2^n) | n <- [0..19]])
--   
print :: Show a => a -> IO () -- | Read a character from the standard input device (same as -- hGetChar stdin). getChar :: IO Char -- | Read a line from the standard input device (same as hGetLine -- stdin). getLine :: IO String -- | The getContents operation returns all user input as a single -- string, which is read lazily as it is needed (same as -- hGetContents stdin). getContents :: IO String -- | The readIO function is similar to read except that it -- signals parse failure to the IO monad instead of terminating -- the program. readIO :: Read a => String -> IO a -- | The readLn function combines getLine and readIO. readLn :: Read a => IO a -- | Select binary mode (True) or text mode (False) on a open -- handle. (See also openBinaryFile.) -- -- This has the same effect as calling hSetEncoding with -- char8, together with hSetNewlineMode with -- noNewlineTranslation. hSetBinaryMode :: Handle -> Bool -> IO () -- | hPutBuf hdl buf count writes count 8-bit -- bytes from the buffer buf to the handle hdl. It -- returns (). -- -- hPutBuf ignores any text encoding that applies to the -- Handle, writing the bytes directly to the underlying file or -- device. -- -- hPutBuf ignores the prevailing TextEncoding and -- NewlineMode on the Handle, and writes bytes directly. -- -- This operation may fail with: -- -- hPutBuf :: Handle -> Ptr a -> Int -> IO () -- | hGetBuf hdl buf count reads data from the handle -- hdl into the buffer buf until either EOF is reached -- or count 8-bit bytes have been read. It returns the number of -- bytes actually read. This may be zero if EOF was reached before any -- data was read (or if count is zero). -- -- hGetBuf never raises an EOF exception, instead it returns a -- value smaller than count. -- -- If the handle is a pipe or socket, and the writing end is closed, -- hGetBuf will behave as if EOF was reached. -- -- hGetBuf ignores the prevailing TextEncoding and -- NewlineMode on the Handle, and reads bytes directly. hGetBuf :: Handle -> Ptr a -> Int -> IO Int hPutBufNonBlocking :: Handle -> Ptr a -> Int -> IO Int -- | hGetBufNonBlocking hdl buf count reads data from the -- handle hdl into the buffer buf until either EOF is -- reached, or count 8-bit bytes have been read, or there is no -- more data available to read immediately. -- -- hGetBufNonBlocking is identical to hGetBuf, except that -- it will never block waiting for data to become available, instead it -- returns only whatever data is available. To wait for data to arrive -- before calling hGetBufNonBlocking, use hWaitForInput. -- -- If the handle is a pipe or socket, and the writing end is closed, -- hGetBufNonBlocking will behave as if EOF was reached. -- -- hGetBufNonBlocking ignores the prevailing TextEncoding -- and NewlineMode on the Handle, and reads bytes directly. -- -- NOTE: on Windows, this function does not work correctly; it behaves -- identically to hGetBuf. hGetBufNonBlocking :: Handle -> Ptr a -> Int -> IO Int