Skip to content

Commit 661a310

Browse files
Rename isBranch to isUnrooted
1 parent 0a48d25 commit 661a310

File tree

6 files changed

+124
-126
lines changed

6 files changed

+124
-126
lines changed

core/src/Streamly/FileSystem/Path.hs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,29 @@
2222
-- of the @filepath@ package, some differences exist due to a slightly
2323
-- different design philosophy focused on better safety.
2424
--
25-
-- = Rooted Paths vs Branches
25+
-- = Rooted vs Unrooted Paths
2626
--
2727
-- To ensure the safety of the path append operation, we distinguish between
28-
-- rooted paths and branch-type paths. A path that starts from an explicit or
29-
-- implicit file system root is called a rooted path or an anchored path. For
30-
-- example, @\/usr\/bin@ is a rooted path with an explicit root directory @/@.
31-
-- Similarly, @.\/bin@ is a rooted path with an implicit root, anchored at the
32-
-- current directory. A path that is not rooted is called a branch type path or
33-
-- unanchored path; for example, @local\/bin@ is a branch.
28+
-- rooted paths and free path segments or unrooted paths. A path that starts
29+
-- from an explicit or implicit file system root is called a rooted path or an
30+
-- anchored path. For example, @\/usr\/bin@ is a rooted path with @/@ as an
31+
-- explicit root directory. Similarly, @.\/bin@ is a rooted path with the
32+
-- current directoy \".\" as an implicit root. A path that is not rooted is
33+
-- called an unrooted path or unanchored path; for example, @local\/bin@ is an
34+
-- unrooted path.
3435
--
3536
-- This distinction ensures the safety of the path append operation. You can
36-
-- append only a branch type path to another path, it does not make sense to
37+
-- append only an unrooted path to another path, it does not make sense to
3738
-- append a rooted path to another path. The default append operation in the
38-
-- Path module checks for this and fails if the operation is invalid. However,
39-
-- the programmer can force the unsafe behavior by using the unsafe append
40-
-- operation. Alternatively, you can drop the root explicitly and use the safe
41-
-- append.
42-
--
43-
-- Rooted vs branch distinction is a stricter form of relative vs absolute path
44-
-- distinction. Essentially, paths relative to the current directory are also
45-
-- treated in the same way as absolute paths, from the perspective of an append
46-
-- operation. The meaning of current directory is context dependent and
47-
-- dynamic, therefore, appending it to another path is not allowed. Only pure
48-
-- branch-type paths (e.g. @local/bin@) can be appended to any other path using
49-
-- safe operations.
39+
-- Path module checks for this and fails if the operation is invalid.
40+
--
41+
-- Rooted vs unrooted distinction is a stricter form of relative vs absolute
42+
-- path distinction. In this model, for better safety, paths relative to the
43+
-- current directory are also treated in the same way as absolute paths, from
44+
-- the perspective of a path append operation. This is because the meaning of
45+
-- current directory is context dependent and dynamic, therefore, appending it
46+
-- to another path is not allowed. Only unrooted path segments (e.g.
47+
-- @local/bin@) can be appended to any other path using safe operations.
5048
--
5149
-- = File vs. Directory Paths
5250
--
@@ -102,7 +100,7 @@ module Streamly.FileSystem.Path
102100

103101
-- * Path Info
104102
, isRooted
105-
, isBranch
103+
, isUnrooted
106104

107105
-- * Joining
108106
, unsafeExtend

core/src/Streamly/FileSystem/Path/Seg.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- Maintainer : streamly@composewell.com
66
-- Portability : GHC
77
--
8-
-- Represent 'Rooted' or 'Branch' type path segments explicitly as separate
8+
-- Represent 'Rooted' or 'Unrooted' type path segments explicitly as separate
99
-- types for the safety of path append operation. A Rooted path is an absolute
1010
-- path or a path that is relative to the current directory with a leading dot.
1111
-- Rooted paths cannot be appended to other paths.
@@ -16,18 +16,18 @@ module Streamly.FileSystem.Path.Seg
1616
(
1717
-- * Types
1818
Rooted
19-
, Branch
19+
, Unrooted
2020
, IsSeg
2121

2222
-- * Statically Verified Path Literals
2323
-- | Quasiquoters.
2424
, rt
25-
, br
25+
, ur
2626

2727
-- * Statically Verified Path Strings
2828
-- | Template Haskell expression splices.
2929
, rtE
30-
, brE
30+
, urE
3131

3232
-- * Operations
3333
, extend

core/src/Streamly/FileSystem/Path/SegNode.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- Maintainer : streamly@composewell.com
66
-- Portability : GHC
77
--
8-
-- Use 'Rooted' or 'Branch' path segment type annotations as well as 'File' and
8+
-- Use 'Rooted' or 'Unrooted' path segment type annotations as well as 'File' and
99
-- 'Dir' node type annotations on the same path for the safety of path append
1010
-- operation. A Rooted path cannot be appended to other paths, and you canno
1111
-- append a path to a 'File' type path.
@@ -18,16 +18,16 @@ module Streamly.FileSystem.Path.SegNode
1818
-- * Statically Verified Path Literals
1919
-- | Quasiquoters.
2020
rtdir
21-
, brdir
21+
, urdir
2222
, rtfile
23-
, brfile
23+
, urfile
2424

2525
-- * Statically Verified Path Strings
2626
-- | Template Haskell expression splices.
2727
, rtdirE
28-
, brdirE
28+
, urdirE
2929
, rtfileE
30-
, brfileE
30+
, urfileE
3131

3232
-- * Operations
3333
, extend

core/src/Streamly/Internal/FileSystem/PosixPath.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ module Streamly.Internal.FileSystem.OS_PATH_TYPE
156156

157157
-- * Path Segment Types
158158
, isRooted
159-
, isBranch
159+
, isUnrooted
160160

161161
-- * Joining
162162
, extendByString
@@ -873,21 +873,21 @@ isRooted (OS_PATH arr) = Common.isRooted Common.OS_NAME arr
873873

874874
-- | A path that is not attached to a root e.g. @a\/b\/c@ or @..\/b\/c@.
875875
--
876-
-- >>> isBranch = not . Path.isRooted
876+
-- >>> isUnrooted = not . Path.isRooted
877877
--
878-
-- >>> isBranch = Path.isBranch . Path.fromString_
878+
-- >>> isUnrooted = Path.isUnrooted . Path.fromString_
879879
--
880-
-- >>> isBranch "x"
880+
-- >>> isUnrooted "x"
881881
-- True
882-
-- >>> isBranch "x/y"
882+
-- >>> isUnrooted "x/y"
883883
-- True
884-
-- >>> isBranch ".."
884+
-- >>> isUnrooted ".."
885885
-- True
886-
-- >>> isBranch "../x"
886+
-- >>> isUnrooted "../x"
887887
-- True
888888
--
889-
isBranch :: OS_PATH_TYPE -> Bool
890-
isBranch = not . isRooted
889+
isUnrooted :: OS_PATH_TYPE -> Bool
890+
isUnrooted = not . isRooted
891891

892892
#ifndef IS_WINDOWS
893893
-- | Like 'extend' but does not check if the second path is rooted.

core/src/Streamly/Internal/FileSystem/PosixPath/Seg.hs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
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
6868
For 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

7676
newtype Rooted a = Rooted a
77-
newtype Branch a = Branch a
77+
newtype Unrooted a = Unrooted a
7878

7979
instance 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.
102102
class IsSeg a
103103

104104
instance 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
112112
liftRooted (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
--
121121
rtE :: String -> Q Exp
122122
rtE = 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
143143
rt :: QuasiQuoter
144144
rt = 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 #-}
165165
extend ::
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

Comments
 (0)