streamly-core
Copyright(c) 2023 Composewell Technologies
LicenseBSD3
Maintainerstreamly@composewell.com
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Internal.FileSystem.PosixPath.Seg

Description

This module provides a type safe path append operation by distinguishing paths between rooted paths and branches. Rooted paths are represented by the Rooted PosixPath type and branches are represented by the Unrooted PosixPath type. Rooted paths are paths that are attached to specific roots in the file system. Rooted paths could be absolute or relative e.g. /usr/bin, ./local/bin, or .. Unrootedes are a paths that are not attached to a specific root e.g. usr/bin, local/bin, or ../bin are branches.

This distinction provides a safe path append operation which cannot fail. These types do not allow appending a rooted path to any other path. Only branches can be appended.

Synopsis

Types

class IsSeg a Source #

Constraint to check if a type has Rooted or Unrooted annotations.

Instances

Instances details
IsSeg (Rooted a) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsSeg (Unrooted a) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

Statically Verified Path Literals

Quasiquoters.

rt :: QuasiQuoter Source #

Generates a Rooted Path type from a quoted literal.

>>> Path.toString (Path.toPath ([rt|/usr|] :: Rooted PosixPath))
"/usr"

ur :: QuasiQuoter Source #

Generates a Unrooted Path type from a quoted literal.

>>> Path.toString (Path.toPath ([ur|usr|] :: Unrooted PosixPath))
"usr"

Statically Verified Path Strings

Template Haskell expression splices.

rtE :: String -> Q Exp Source #

Generates a Haskell expression of type Rooted PosixPath.

urE :: String -> Q Exp Source #

Generates a Haskell expression of type Unrooted PosixPath.

Operations

join :: (IsSeg (a PosixPath), IsPath PosixPath (a PosixPath)) => a PosixPath -> Unrooted PosixPath -> a PosixPath Source #

Append a Unrooted type path to a Rooted path or Unrooted path.

>>> Path.toString (Path.toPath (Seg.join [rt|/usr|] [ur|bin|] :: Rooted PosixPath))
"/usr/bin"
>>> Path.toString (Path.toPath (Seg.join [ur|usr|] [ur|bin|] :: Unrooted PosixPath))
"usr/bin"