HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulestreamly-core-0.2.2Haskell2010

Streamly.Internal.FileSystem.Path

Well typed and flexible file systems paths, preserving the OS and filesystem encoding.

You can choose the level of type safety you want. Path is the basic path type which can represent a file, directory, absolute or relative path with no restrictions. Depending on how much type safety you want you can choose appropriate type wrappers to wrap Path. File Path mandates the path to be a file whereas Abs (File Path) mandates it to be an absolute path representing a file.

You can upgrade or downgrade the safety. Whenever a less restrictive path type is converted to a more restrctive path type the conversion involves checks and it may fail. However, a more restrictive path type can be freely converted to a less restrictive one.

See the streamly-filepath package for interworking with the OsPath type. The Path type can be converted to and from OsPath type at zero cost since the underlying representation of both is the same.

  • 5 types
  • 1 class
  • 30 values

Path Types

5 declarations
newtypenewtype Path
#

A type representing file system paths for directories or files.

Constructors

Instances9IsPath, …
  • IsPath PathDefined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Dir Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (File Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
newtypenewtype File a
#

A type representing a file path.

Instances3IsPath
  • IsPath (Abs (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (File Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
newtypenewtype Dir a
#

A type representing a directory path.

Instances3IsPath
  • IsPath (Abs (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Dir Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
newtypenewtype Abs a
#

A type representing absolute paths.

Instances3IsPath
  • IsPath (Abs Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
newtypenewtype Rel a
#

A type representing relative paths.

Instances3IsPath
  • IsPath (Rel Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path

Conversions

2 declarations
classclass IsPath a where
#

A member of IsPath knows how to convert to and from the Path type.

Methods

  • fromPathUnsafe :: Path -> a

    Like fromPath but does not check the properties of Path. Provides performance and simplicity when we know that the properties of the path are already verified, for example, when we get the path from the file system or the OS APIs.

  • fromPath :: MonadThrow m => Path -> m a

    Convert a raw Path to other forms of well-typed paths. It may fail if the path does not satisfy the properties of the target type.

    Path components may have limits. Total path length may have a limit.

  • toPath :: a -> Path

    Convert a well-typed path to a raw Path. Never fails.

Instances9IsPath, …
  • IsPath PathDefined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Abs (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Dir Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (File Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel Path)Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (Dir Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
  • IsPath (Rel (File Path))Defined in streamly-core-0.2.2 · Streamly.Internal.FileSystem.Path
valueadaptPath :: (MonadThrow m, IsPath a, IsPath b) => a -> m b
#

Convert a path type to another path type. This operation may fail with a PathException when converting a less restrictive path type to a more restrictive one.

Construction

4 declarations
valuefromChunk :: MonadThrow m => Array Word8 -> m Path
#

On Posix it may fail if the byte array contains null characters. On Windows the array passed must be a multiple of 2 bytes as the underlying representation uses Word16.

Throws InvalidPath.

Unsafe: On Posix, a path cannot contain null characters. On Windows, the array passed must be a multiple of 2 bytes as the underlying representation uses Word16.

valuefromString :: MonadThrow m => [Char] -> m Path
#

Encode a Unicode string to Path using strict UTF-8 encoding on Posix. On Posix it may fail if the stream contains null characters. TBD: Use UTF16LE on Windows.

valuefromChars :: MonadThrow m => Stream Identity Char -> m Path
#

Encode a Unicode char stream to Path using strict UTF-8 encoding on Posix. On Posix it may fail if the stream contains null characters. TBD: Use UTF16LE on Windows.

Statically Verified Literals

9 declarations
valuepath :: QuasiQuoter
#

Generates a Path type from an interpolated string literal.

Unimplemented

valueabs :: QuasiQuoter
#

Generates an Abs Path type from an interpolated string literal.

Unimplemented

valuerel :: QuasiQuoter
#

Generates an Rel Path type from an interpolated string literal.

Unimplemented

valuedir :: QuasiQuoter
#

Generates an Dir Path type from an interpolated string literal.

Unimplemented

valuefile :: QuasiQuoter
#

Generates an File Path type from an interpolated string literal.

Unimplemented

valueabsdir :: QuasiQuoter
#

Generates an Abs (Dir Path) type from an interpolated string literal.

Unimplemented

valuereldir :: QuasiQuoter
#

Generates an Rel (Dir Path) type from an interpolated string literal.

Unimplemented

valueabsfile :: QuasiQuoter
#

Generates an Abs (File Path) type from an interpolated string literal.

Unimplemented

valuerelfile :: QuasiQuoter
#

Generates an Rel (File Path) type from an interpolated string literal.

Unimplemented

Statically Verified Strings

9 declarations

Elimination

3 declarations
valuetoString :: Path -> [Char]
#

Decode the path to a Unicode string using strict UTF-8 decoding on Posix. TBD: Use UTF16LE on Windows.

valuetoChars :: Monad m => Path -> Stream m Char
#

Decode the path to a stream of Unicode chars using strict UTF-8 decoding on Posix. TBD: Use UTF16LE on Windows.

Operations

4 declarations
valueprimarySeparator :: Char
#

Primary path separator character, / on Posix and \ on Windows. Windows supports / too as a separator. Please use isSeparator for testing if a char is a separator char.

valueisSeparator :: Char -> Bool
#

On Posix only / is a path separator but in windows it could be either / or \.

valueextendPath :: Path -> Path -> Path
#

Like extendDir but for the less restrictive Path type which will always create a syntactically valid Path type but it may not be semantically valid because we may append an absolute path or we may append to a file path. The onus lies on the user to ensure that the first path is not a file and the second path is not absolute.