|
5 | 5 | |
6 | 6 | -- Portability : GHC |
7 | 7 | -- |
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. |
10 | 10 | -- |
11 | 11 | -- /Flexible/: you can choose the level of type safety you want. 'Path' is the |
12 | 12 | -- basic path type which can represent a file, directory, absolute or relative |
13 | 13 | -- path with no restrictions. Depending on how much type safety you want, you |
14 | 14 | -- can choose appropriate type wrappers or a combination of those to wrap the |
15 | 15 | -- 'Path' type. |
16 | 16 | -- |
17 | | --- = Rooted Paths vs Path Segments |
| 17 | +-- = Rooted Paths vs Branches |
18 | 18 | -- |
19 | 19 | -- 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 |
21 | 21 | -- explicit root in the file system is a rooted path, for example, @\/usr\/bin@ |
22 | 22 | -- is a rooted path starting from an explicit file system root directory @/@. |
23 | 23 | -- 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. |
26 | 26 | -- |
27 | 27 | -- 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 |
29 | 29 | -- not make sense to append a rooted path to another rooted path. The default |
30 | 30 | -- append operation in the Path module checks for this and fails if the |
31 | 31 | -- 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. |
34 | 34 | -- |
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. |
42 | 42 | -- |
43 | 43 | -- = Absolute vs Relative Rooted Paths |
44 | 44 | -- |
45 | 45 | -- Rooted paths can be absolute or relative. Absolute paths have an absolute |
46 | 46 | -- root e.g. @\/usr\/bin@. Relative paths have a dynamic or relative root e.g. |
47 | 47 | -- @.\/local\/bin@, or @.@, in these cases the root is current directory which |
48 | 48 | -- 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. |
50 | 51 | -- |
51 | 52 | -- = File vs Directory Paths |
52 | 53 | -- |
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. |
59 | 60 | -- |
60 | 61 | -- By default a path with a trailing separator is implicitly considered a |
61 | 62 | -- directory path. However, the absence of a trailing separator does not convey |
62 | 63 | -- 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 |
64 | 65 | -- separator. However, when creating a typed path of 'File' type the conversion |
65 | 66 | -- fails unless we explicitly drop the trailing separator. |
66 | 67 | -- |
67 | 68 | -- = Flexible Typing |
68 | 69 | -- |
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 |
71 | 72 | -- 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. |
75 | 76 | -- |
76 | 77 | -- 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. |
82 | 83 | -- |
83 | 84 | -- = Extensibility |
84 | 85 | -- |
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. |
87 | 88 | -- |
88 | 89 | -- = Compatibility |
89 | 90 | -- |
90 | 91 | -- Any path type can be converted to the 'FilePath' type using the 'toString' |
91 | 92 | -- operation. Operations to convert to and from 'OsPath' type at zero cost are |
92 | 93 | -- 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. |
94 | 96 | -- |
95 | 97 | -- = String Creation Quasiquoter |
96 | 98 | -- |
|
0 commit comments