1919--
2020-- This module provides a type safe path append operation by distinguishing
2121-- paths between rooted paths and branches. Rooted paths are represented by the
22- -- @Rooted OS_PATH@ type and branches are represented by the @Branch OS_PATH@
22+ -- @Rooted OS_PATH@ type and branches are represented by the @Unrooted OS_PATH@
2323-- type. Rooted paths are paths that are attached to specific roots in the file
2424-- system. Rooted paths could be absolute or relative e.g. @\/usr\/bin@,
25- -- @.\/local\/bin@, or @.@. Branches are a paths that are not attached to a
25+ -- @.\/local\/bin@, or @.@. Unrootedes are a paths that are not attached to a
2626-- specific root e.g. @usr\/bin@, @local\/bin@, or @../bin@ are branches.
2727--
2828-- This distinction provides a safe path append operation which cannot fail.
@@ -33,18 +33,18 @@ module Streamly.Internal.FileSystem.OS_PATH.Seg
3333 (
3434 -- * Types
3535 Rooted (.. )
36- , Branch (.. )
36+ , Unrooted (.. )
3737 , IsSeg
3838
3939 -- * Statically Verified Path Literals
4040 -- | Quasiquoters.
4141 , rt
42- , br
42+ , ur
4343
4444 -- * Statically Verified Path Strings
4545 -- | Template Haskell expression splices.
4646 , rtE
47- , brE
47+ , urE
4848
4949 -- * Operations
5050 , extend
@@ -68,13 +68,13 @@ import qualified Streamly.Internal.FileSystem.OS_PATH as OsPath
6868For APIs that have not been released yet.
6969
7070>>> import Streamly.Internal.FileSystem.PosixPath (PosixPath)
71- >>> import Streamly.Internal.FileSystem.PosixPath.Seg (Rooted, Branch , rt, br )
71+ >>> import Streamly.Internal.FileSystem.PosixPath.Seg (Rooted, Unrooted , rt, ur )
7272>>> import qualified Streamly.Internal.FileSystem.PosixPath as Path
7373>>> import qualified Streamly.Internal.FileSystem.PosixPath.Seg as Seg
7474-}
7575
7676newtype Rooted a = Rooted a
77- newtype Branch a = Branch a
77+ newtype Unrooted a = Unrooted a
7878
7979instance IsPath OS_PATH (Rooted OS_PATH ) where
8080 unsafeFromPath = Rooted
@@ -87,22 +87,22 @@ instance IsPath OS_PATH (Rooted OS_PATH) where
8787 ++ OsPath. toString p
8888 toPath (Rooted p) = p
8989
90- instance IsPath OS_PATH (Branch OS_PATH ) where
91- unsafeFromPath = Branch
90+ instance IsPath OS_PATH (Unrooted OS_PATH ) where
91+ unsafeFromPath = Unrooted
9292 fromPath p =
93- if OsPath. isBranch p
94- then pure (Branch p)
93+ if OsPath. isUnrooted p
94+ then pure (Unrooted p)
9595 -- XXX Add more detailed error msg with all valid examples.
9696 else throwM $ InvalidPath
9797 $ " Must be a path segment, not a specific location: "
9898 ++ OsPath. toString p
99- toPath (Branch p) = p
99+ toPath (Unrooted p) = p
100100
101- -- | Constraint to check if a type has Rooted or Branch annotations.
101+ -- | Constraint to check if a type has Rooted or Unrooted annotations.
102102class IsSeg a
103103
104104instance IsSeg (Rooted a )
105- instance IsSeg (Branch a )
105+ instance IsSeg (Unrooted a )
106106
107107------------------------------------------------------------------------------
108108-- Statically Verified Strings
@@ -112,19 +112,19 @@ liftRooted :: Rooted OS_PATH -> Q Exp
112112liftRooted (Rooted p) =
113113 [| OsPath. unsafeFromString $ (lift $ OsPath. toString p) :: Rooted OS_PATH | ]
114114
115- liftBranch :: Branch OS_PATH -> Q Exp
116- liftBranch ( Branch p) =
117- [| OsPath. unsafeFromString $ (lift $ OsPath. toString p) :: Branch OS_PATH | ]
115+ lifUntooted :: Unrooted OS_PATH -> Q Exp
116+ lifUntooted ( Unrooted p) =
117+ [| OsPath. unsafeFromString $ (lift $ OsPath. toString p) :: Unrooted OS_PATH | ]
118118
119119-- | Generates a Haskell expression of type @Rooted OS_PATH@.
120120--
121121rtE :: String -> Q Exp
122122rtE = either (error . show ) liftRooted . OsPath. fromString
123123
124- -- | Generates a Haskell expression of type @Branch OS_PATH@.
124+ -- | Generates a Haskell expression of type @Unrooted OS_PATH@.
125125--
126- brE :: String -> Q Exp
127- brE = either (error . show ) liftBranch . OsPath. fromString
126+ urE :: String -> Q Exp
127+ urE = either (error . show ) lifUntooted . OsPath. fromString
128128
129129------------------------------------------------------------------------------
130130-- Statically Verified Literals
@@ -143,29 +143,29 @@ brE = either (error . show) liftBranch . OsPath.fromString
143143rt :: QuasiQuoter
144144rt = mkQ rtE
145145
146- -- | Generates a @Branch Path@ type from a quoted literal.
146+ -- | Generates a @Unrooted Path@ type from a quoted literal.
147147--
148- -- >>> Path.toString ([br |usr|] :: Branch PosixPath)
148+ -- >>> Path.toString ([ur |usr|] :: Unrooted PosixPath)
149149-- "usr"
150150--
151- br :: QuasiQuoter
152- br = mkQ brE
151+ ur :: QuasiQuoter
152+ ur = mkQ urE
153153
154154-- The only safety we need for paths is: (1) The first path can only be a Dir
155- -- type path, and (2) second path can only be a Branch path.
155+ -- type path, and (2) second path can only be a Unrooted path.
156156
157- -- | Append a 'Branch ' type path to a 'Rooted' path or 'Branch ' path.
157+ -- | Append a 'Unrooted ' type path to a 'Rooted' path or 'Unrooted ' path.
158158--
159- -- >>> Path.toString (Seg.extend [rt|/usr|] [br |bin|] :: Rooted PosixPath)
159+ -- >>> Path.toString (Seg.extend [rt|/usr|] [ur |bin|] :: Rooted PosixPath)
160160-- "/usr/bin"
161- -- >>> Path.toString (Seg.extend [br |usr|] [br |bin|] :: Branch PosixPath)
161+ -- >>> Path.toString (Seg.extend [ur |usr|] [ur |bin|] :: Unrooted PosixPath)
162162-- "usr/bin"
163163--
164164{-# INLINE extend #-}
165165extend ::
166166 (
167167 IsSeg (a OS_PATH )
168168 , IsPath OS_PATH (a OS_PATH )
169- ) => a OS_PATH -> Branch OS_PATH -> a OS_PATH
170- extend a (Branch c) =
169+ ) => a OS_PATH -> Unrooted OS_PATH -> a OS_PATH
170+ extend a (Unrooted c) =
171171 unsafeFromPath $ OsPath. unsafeExtend (toPath a) (toPath c)
0 commit comments