Skip to content

Commit 0125c61

Browse files
Update docs of Path module according to new naming
1 parent 4a5012a commit 0125c61

File tree

5 files changed

+77
-71
lines changed

5 files changed

+77
-71
lines changed

core/src/Streamly/FileSystem/Path.hs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,94 @@
55
-- Maintainer : [email protected]
66
-- Portability : GHC
77
--
8-
-- Well typed, flexible, extensible and efficient file systems paths,
9-
-- preserving the OS and filesystem encoding.
8+
-- File system paths with flexible (gradual) typing, extensible,
9+
-- high-performance, preserving the OS and filesystem encoding.
1010
--
1111
-- /Flexible/: you can choose the level of type safety you want. 'Path' is the
1212
-- basic path type which can represent a file, directory, absolute or relative
1313
-- path with no restrictions. Depending on how much type safety you want, you
1414
-- can choose appropriate type wrappers or a combination of those to wrap the
1515
-- 'Path' type.
1616
--
17-
-- = Rooted Paths vs Path Segments
17+
-- = Rooted Paths vs Branches
1818
--
1919
-- For the safety of the path append operation we make the distinction of
20-
-- rooted paths vs path segments. A path that starts from some implicit or
20+
-- rooted paths vs branches. A path that starts from some implicit or
2121
-- explicit root in the file system is a rooted path, for example, @\/usr\/bin@
2222
-- is a rooted path starting from an explicit file system root directory @/@.
2323
-- Similarly, @.\/bin@ is a path with an implicit root, this path is hanging
24-
-- from the current directory. A path that is not rooted is called a path
25-
-- segment e.g. @local\/bin@ is a segment.
24+
-- from the current directory. A path that is not rooted is called a branch
25+
-- e.g. @local\/bin@ is a branch.
2626
--
2727
-- This distinction affords safety to the path append operation. We can always
28-
-- append a segment to a rooted path or to another segment. However, it does
28+
-- append a branch to a rooted path or to another branch. However, it does
2929
-- not make sense to append a rooted path to another rooted path. The default
3030
-- append operation in the Path module checks for this and fails if the
3131
-- operation is incorrect. However, the programmer can force it by using the
32-
-- unsafe version of append operation. You can also drop the root explicitly
33-
-- and use the safe append operation.
32+
-- unsafe version of the append operation. You can also drop the root
33+
-- explicitly and use the safe append operation.
3434
--
35-
-- The "Streamly.FileSystem.Path.LocSeg" module provides explicit typing of
36-
-- rooted paths vs path segments. Rooted paths are represented by the @Loc
37-
-- Path@ type and path segments are represented by the @Seg Path@ type. If you
38-
-- use the 'Path' type then append can fail if you try to append a rooted
39-
-- location to another path, but if you use @Loc Path@ or @Seg Path@ types then
40-
-- append can never fail at run time as the types would not allow it at compile
41-
-- time.
35+
-- The "Streamly.FileSystem.Path.Seg" module provides explicit typing of path
36+
-- segments e.g. rooted paths vs branches. Rooted paths are represented by the
37+
-- @Rooted Path@ type and branches are represented by the @Branch Path@ type.
38+
-- If you use the 'Path' type then append can fail if you try to append a
39+
-- rooted path to another path, but if you use @Rooted Path@ and @Branch Path@
40+
-- types then append can never fail at run time as the types would not allow it
41+
-- at compile time.
4242
--
4343
-- = Absolute vs Relative Rooted Paths
4444
--
4545
-- Rooted paths can be absolute or relative. Absolute paths have an absolute
4646
-- root e.g. @\/usr\/bin@. Relative paths have a dynamic or relative root e.g.
4747
-- @.\/local\/bin@, or @.@, in these cases the root is current directory which
4848
-- is not absolute but can change dynamically. Note that there is no type level
49-
-- distinction for absolute and relative paths.
49+
-- distinction for absolute and relative paths. The append operation requires a
50+
-- distinction between Rooted and Branch only.
5051
--
5152
-- = File vs Directory Paths
5253
--
53-
-- Independently of the rooted or segment distinction you can also make the
54-
-- distinction between files and directories using the
55-
-- "Streamly.FileSystem.Path.FileDir" module. @File Path@ type represents a
56-
-- file whereas @Dir Path@ represents a directory. It provides safety against
57-
-- appending a path to a file. Append operation does not allow appending to
58-
-- 'File' types.
54+
-- Independent of the rooted or branch distinction you can also make a type
55+
-- level distinction between file and directory type nodes using the
56+
-- "Streamly.FileSystem.Path.Node" module. @File Path@ type represents a file
57+
-- whereas @Dir Path@ represents a directory. This distinction provides safety
58+
-- against appending a path to a file. Append operation does not allow
59+
-- appending to 'File' types.
5960
--
6061
-- By default a path with a trailing separator is implicitly considered a
6162
-- directory path. However, the absence of a trailing separator does not convey
6263
-- any information, it could either be a directory or a file. Thus the append
63-
-- operation allows appending to even the paths that do not have a trailing
64+
-- operation allows appending to even paths that do not have a trailing
6465
-- separator. However, when creating a typed path of 'File' type the conversion
6566
-- fails unless we explicitly drop the trailing separator.
6667
--
6768
-- = Flexible Typing
6869
--
69-
-- You can use the 'Loc', 'Seg' or 'Dir', 'File' types independent of each
70-
-- other by using only the required module. If you want both types of
70+
-- You can use the 'Rooted', 'Branch' or 'Dir', 'File' types independent of
71+
-- each other by using only the required module. If you want both types of
7172
-- distinctions then you can use them together as well using the
72-
-- "Streamly.FileSystem.Path.Typed" module. For example, the @Loc (Dir Path)@
73-
-- represents a rooted path which is a directory. You can only append to a path
74-
-- that has 'Dir' in it and you can only append a 'Seg' type.
73+
-- "Streamly.FileSystem.Path.SegNode" module. For example, the @Rooted (Dir
74+
-- Path)@ represents a rooted path which is a directory. You can only append to
75+
-- a path that has 'Dir' in it and you can only append a 'Branch' type.
7576
--
7677
-- You can choose to use just the basic 'Path' type or any combination of safer
77-
-- types. You can upgrade or downgrade the safety using the @adapt@ operation.
78-
-- Whenever a less restrictive path type is converted to a more restrictive
79-
-- path type, the conversion involves run-time checks and it may fail. However,
80-
-- a more restrictive path type can be freely converted to a less restrictive
81-
-- one.
78+
-- types. You can upgrade or downgrade the safety by converting types using the
79+
-- @adapt@ operation. Whenever a less restrictive path type is converted to a
80+
-- more restrictive path type, the conversion involves run-time checks and it
81+
-- may fail. However, a more restrictive path type can be freely converted to a
82+
-- less restrictive one.
8283
--
8384
-- = Extensibility
8485
--
85-
-- Extensible, you can define your own newtype wrappers similar to 'File' or
86-
-- 'Dir' to provide custom restrictions if you want.
86+
-- You can define your own newtype wrappers similar to 'File' or 'Dir' to
87+
-- provide custom restrictions if you want.
8788
--
8889
-- = Compatibility
8990
--
9091
-- Any path type can be converted to the 'FilePath' type using the 'toString'
9192
-- operation. Operations to convert to and from 'OsPath' type at zero cost are
9293
-- provided in the @streamly-filepath@ package. This is possible because the
93-
-- types use the same underlying representation as the 'OsPath' type.
94+
-- types use an underlying representation which is compatible with the 'OsPath'
95+
-- type.
9496
--
9597
-- = String Creation Quasiquoter
9698
--

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@
2424
-- in the presence of symlinks it could be a DAG or a graph, because directory
2525
-- symlinks can create cycles.
2626
--
27-
-- == Location and Segments
27+
-- == Rooted and Branch paths
2828
--
29-
-- We make two distinctions for paths, a path could refer to a location or it
30-
-- could refer to a segment or segments.
29+
-- We make two distinctions for paths, a path may a specific filesystem root
30+
-- attached to it or it may be a free branch without a root attached.
3131
--
32-
-- A path that refers to a particular object in the file system is called a
33-
-- location e.g. /usr is a location, . is a location, ./bin is a location. A
34-
-- location could be absolute e.g. /usr or it could be relative e.g. ./bin . A
35-
-- location always has two components, a specific "root" which could be
36-
-- explicit or implicit, and a path segment relative to the root. A location
37-
-- with a fixed root is known as an absolute location whereas a location with
38-
-- an implicit root e.g. "./bin" is known as a relative location.
32+
-- A path that has a root attached to it is called a rooted path e.g. /usr is a
33+
-- rooted path, . is a rooted path, ./bin is a rooted path. A rooted path could
34+
-- be absolute e.g. /usr or it could be relative e.g. ./bin . A rooted path
35+
-- always has two components, a specific "root" which could be explicit or
36+
-- implicit, and a path segment relative to the root. A rooted path with a
37+
-- fixed root is known as an absolute path whereas a rooted path with an
38+
-- implicit root e.g. "./bin" is known as a relative path.
3939
--
40-
-- A path that does not refer to a particular location but defines steps to go
41-
-- from some place to another is a path segment. For example, "local/bin" is a
42-
-- path segment whereas "./local/bin" is a location.
40+
-- A path that does not have a root attached but defines steps to go from some
41+
-- place to another is a path branch. For example, "local/bin" is a path branch
42+
-- whereas "./local/bin" is a rooted path.
4343
--
44-
-- Locations can never be appended to another location or to a path segment
45-
-- whereas a segment can be appended.
44+
-- Rooted paths can never be appended to any other path whereas a branch can be
45+
-- appended.
4646
--
4747
-- == Comparing Paths
4848
--
49-
-- We can compare two absolute locations or path segments but we cannot compare
50-
-- two relative locations. If each component of the path is the same then the
51-
-- paths are considered to be equal.
49+
-- We can compare two absolute rooted paths or path branches but we cannot
50+
-- compare two relative rooted paths. If each component of the path is the same
51+
-- then the paths are considered to be equal.
5252
--
5353
-- == Implicit Roots (.)
5454
--
@@ -68,16 +68,16 @@
6868
-- We can treat @.\/bin\/ls@ as an absolute path with "." as an implicit root.
6969
-- The relative path is "bin/ls" which represents steps from somewhere to
7070
-- somewhere else rather than a particular location. We can also call @./bin@
71-
-- as a "located path" as it points to particular location rather than "steps"
72-
-- from one place to another. If we want to append such paths we need to first
73-
-- make them explicitly relative by dropping the implicit root. Or we can use
74-
-- unsafeAppend to force it anyway or unsafeCast to convert absolute to
75-
-- relative.
71+
-- as a "rooted path" as it starts from particular location rather than
72+
-- defining "steps" to go from one place to another. If we want to append such
73+
-- paths we need to first make them explicitly relative by dropping the
74+
-- implicit root. Or we can use unsafeAppend to force it anyway or unsafeCast
75+
-- to convert absolute to relative.
7676
--
77-
-- On these absolute (located/Loc) paths if we use takeRoot, it should return
77+
-- On these absolute (Rooted) paths if we use takeRoot, it should return
7878
-- RootCurDir, RootCurDrive and @Root Path@ to distinguish @./@, @/@, @C:/@. We
79-
-- could represent them by different types but that would make the types even more
80-
-- complicated. So runtime checks are are a good balance.
79+
-- could represent them by different types but that would make the types even
80+
-- more complicated. So runtime checks are are a good balance.
8181
--
8282
-- Path comparison should return EqTrue, EqFalse or EqUnknown. If we compare
8383
-- these absolute/located paths having implicit roots then result should be

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ unsafeAppend (OS_PATH a) (OS_PATH b) =
366366
$ Common.unsafeAppend
367367
Common.OS_NAME (Common.toString Unicode.UNICODE_DECODER) a b
368368

369-
-- | Append a OS_PATH to another. Fails if the second path refers to a location
370-
-- and not a path segment.
369+
-- XXX Should we fail if the first path does not have a trailing separator i.e.
370+
-- it is not a directory?
371+
372+
-- | Append a OS_PATH to another. Fails if the second path refers to a rooted
373+
-- path and not a branch. Use 'unsafeAppend' to avoid failure if you know it is
374+
-- ok to append the path.
371375
--
372376
-- >>> Path.toString $ Path.append [path|/usr|] [path|bin|]
373377
-- "/usr/bin"

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ rtdir = mkQ rtdirE
220220
brdir :: QuasiQuoter
221221
brdir = mkQ brdirE
222222

223-
-- | Generates an @Rooted (File OS_PATH)@ type from a quoted literal.
223+
-- | Generates a @Rooted (File OS_PATH)@ type from a quoted literal.
224224
--
225-
-- >>> Path.toString ([rtfile|/usr|] :: Rooted (File PosixPath))
226-
-- "/usr"
225+
-- >>> Path.toString ([rtfile|/x.txt|] :: Rooted (File PosixPath))
226+
-- "/x.txt"
227227
--
228228
rtfile :: QuasiQuoter
229229
rtfile = mkQ rtfileE
230230

231-
-- | Generates an @Branch (File OS_PATH)@ type from a quoted literal.
231+
-- | Generates a @Branch (File OS_PATH)@ type from a quoted literal.
232232
--
233233
-- >>> Path.toString ([brfile|x.txt|] :: Branch (File PosixPath))
234234
-- "x.txt"

core/streamly-core.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ description:
3737
This package covers some or all of the functionality covered
3838
by @streaming, pipes, conduit, list-t, logic-t, foldl, attoparsec,
3939
array, primitive, vector, vector-algorithms, binary, cereal, store,
40-
bytestring, text, stringsearch, interpolate@. Streamly provides a
41-
consistent, concise, modular and performant interface for all this
40+
bytestring, text, stringsearch, interpolate, filepath, path@. Streamly
41+
provides a consistent, concise, modular and performant interface for all this
4242
functionality.
4343
.
4444
Note: The dependencies "heaps" and "monad-control" are included in

0 commit comments

Comments
 (0)