foundation-0.0.3: Alternative prelude with batteries and no dependencies

License | BSD-style
Maintainer | foundation
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Foundation.VFS

Contents

- FilePath
  - conversion

Description

Synopsis

- class Path path where
  - type PathEnt path
  - type PathPrefix path
  - type PathSuffix path
- filename :: (Path path, Monoid (PathEnt path)) => path -> PathEnt path
- parent :: Path path => path -> path
- prefix :: Path path => path -> PathPrefix path
- suffix :: Path path => path -> PathSuffix path
- data FilePath
- data FileName
- filePathToString :: FilePath -> String
- filePathToLString :: FilePath -> [Char]

# Documentation

class Path path where #

Path type class

defines the Path associated types and basic functions to implement related to the path manipulation

# TODO, add missing enhancement:

    splitExtension :: PathEnt path -> (PathEnt path, PathEnt path)
    addExtension  :: PathEnt path -> PathEnt path -> PathEnt path
    (.) :: path -> PathEnt path -> path
    (-.) :: path -> PathEnt path -> path

Minimal complete definition

(</>), splitPath, buildPath

Associated Types

type PathEnt path #

the associated PathEntity of the given `path` this type is the minimal element contained in the Path a Path is not a collection but it is possible to see this associated type equivalent to the `Element` type family

type PathPrefix path #

the associated prefix of the given `path`

in the case of a `FilePath`, it is a void (i.e. `()`) in the case of a `URI`, it is the schema, host, port...

type PathSuffix path #

the associated suffix of the given path

in the case of the `FilePath`, it is a void (i.e. `()`) in the case of the `URI`, it is a the query, the fragment

Methods

(</>) :: path -> PathEnt path -> path #

join a path entity to a given path

splitPath :: path -> (PathPrefix path, [PathEnt path], PathSuffix path) #

split the path into the associated elements

buildPath :: (PathPrefix path, [PathEnt path], PathSuffix path) -> path #

build the path from the associated elements

Instances

Path URI # |
Associated Types type PathEnt URI :: * # type PathPrefix URI :: * # type PathSuffix URI :: * # Methods (</>) :: URI -> PathEnt URI -> URI # splitPath :: URI -> (PathPrefix URI, [PathEnt URI], PathSuffix URI) # buildPath :: (PathPrefix URI, [PathEnt URI], PathSuffix URI) -> URI #
Path FilePath # |
Associated Types type PathEnt FilePath :: * # type PathPrefix FilePath :: * # type PathSuffix FilePath :: * # Methods (</>) :: FilePath -> PathEnt FilePath -> FilePath # splitPath :: FilePath -> (PathPrefix FilePath, [PathEnt FilePath], PathSuffix FilePath) # buildPath :: (PathPrefix FilePath, [PathEnt FilePath], PathSuffix FilePath) -> FilePath #

filename :: (Path path, Monoid (PathEnt path)) => path -> PathEnt path #

get the filename of the given path

If there is no filename, you will receive the `mempty` of the `PathEnt`

    >>> filename ("foo.hs" :: FilePath)
    foo.hs

    >>> filename ("foo/bar/baz.hs" :: FilePath)
    baz.hs

parent :: Path path => path -> path #

parent is only going to drop the filename.

if you actually want to reference to the parent directory, simply uses:

    parent "." = "." <> ".."

    >>> parent ("foo.hs" :: FilePath)
    .

    >>> parent ("foo/bar/baz.hs" :: FilePath)
    foo/bar

prefix :: Path path => path -> PathPrefix path #

get the path prefix information

    >>> prefix ("/home/tab" :: FilePath)
    Absolute

    >>> prefix ("home/tab" :: FilePath)
    Relative

or for URI (TODO, not yet accurate)

    prefix "http://github.com/vincenthz/hs-foundation?w=1"
       == URISchema http Nothing Nothing "github.com" Nothing

suffix :: Path path => path -> PathSuffix path #

get the path suffix information

    >>> suffix ("/home/tab" :: FilePath)
    ()

or for URI (TODO, not yet accurate)

    suffix "http://github.com/vincenthz/hs-foundation?w=1"
       == URISuffix (["w", "1"], Nothing)

# FilePath

data FilePath #

FilePath is a collection of FileName

TODO: Eq and Ord are implemented using Show This is not very efficient and would need to be improved Also, it is possible the ordering is not necessary what we want in this case.

A FilePath is one of the following:

- An Absolute:
- starts with one of the follwing "/"
- A relative:
- don't start with a "/"
- authorised:
- "/"
- "filepath"
- "."
- ".."
- "workhaskellhs-foundation"
- unauthorised
- "path//"

Instances

Eq FilePath # |
Methods (==) :: FilePath -> FilePath -> Bool # (/=) :: FilePath -> FilePath -> Bool #
Ord FilePath # |
Methods compare :: FilePath -> FilePath -> Ordering # (<) :: FilePath -> FilePath -> Bool # (<=) :: FilePath -> FilePath -> Bool # (>) :: FilePath -> FilePath -> Bool # (>=) :: FilePath -> FilePath -> Bool # max :: FilePath -> FilePath -> FilePath # min :: FilePath -> FilePath -> FilePath #
Show FilePath # |
Methods showsPrec :: Int -> FilePath -> ShowS # show :: FilePath -> String # showList :: [FilePath] -> ShowS #
IsString FilePath # |
Methods fromString :: String -> FilePath #
Path FilePath # |
Associated Types type PathEnt FilePath :: * # type PathPrefix FilePath :: * # type PathSuffix FilePath :: * # Methods (</>) :: FilePath -> PathEnt FilePath -> FilePath # splitPath :: FilePath -> (PathPrefix FilePath, [PathEnt FilePath], PathSuffix FilePath) # buildPath :: (PathPrefix FilePath, [PathEnt FilePath], PathSuffix FilePath) -> FilePath #
type PathEnt FilePath # |
type PathEnt FilePath = FileName
type PathPrefix FilePath # |
type PathPrefix FilePath = Relativity
type PathSuffix FilePath # |
type PathSuffix FilePath = ()

data FileName #

A filename (or path entity) in the FilePath

- Authorised
- ""
- "."
- ".."
- "foundation"
- Unauthorised
- "/"
- "file/"
- "/file"
- "file/path"

Instances

Eq FileName # |
Methods (==) :: FileName -> FileName -> Bool # (/=) :: FileName -> FileName -> Bool #
Show FileName # |
Methods showsPrec :: Int -> FileName -> ShowS # show :: FileName -> String # showList :: [FileName] -> ShowS #
IsString FileName # |
Methods fromString :: String -> FileName #
Monoid FileName # |
Methods mempty :: FileName # mappend :: FileName -> FileName -> FileName # mconcat :: [FileName] -> FileName #

## conversion

filePathToString :: FilePath -> String #

filePathToLString :: FilePath -> [Char] #

conversion of a FilePath into a list of Char

this function may throw exceptions