Skip to content

Commit f34ba86

Browse files
committed
Merge pull request #2 from garyb/newtype-instances
Add instances for DirName and FileName new types
2 parents 3ef5f5f + 82385a2 commit f34ba86

File tree

2 files changed

+170
-82
lines changed

2 files changed

+170
-82
lines changed

MODULES.md

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ newtype FileName
5959

6060
A newtype around a file name.
6161

62+
#### `runFileName`
63+
64+
``` purescript
65+
runFileName :: FileName -> String
66+
```
67+
68+
Unwraps the `FileName` newtype.
69+
6270
#### `DirName`
6371

6472
``` purescript
@@ -68,28 +76,36 @@ newtype DirName
6876

6977
A newtype around a directory name.
7078

79+
#### `runDirName`
80+
81+
``` purescript
82+
runDirName :: DirName -> String
83+
```
84+
85+
Unwraps the `DirName` newtype.
86+
7187
#### `Path`
7288

7389
``` purescript
7490
data Path a b s
7591
```
7692

77-
A type that describes a Path. All flavors of paths are described by this
78-
type, whether they are absolute or relative paths, whether they
93+
A type that describes a Path. All flavors of paths are described by this
94+
type, whether they are absolute or relative paths, whether they
7995
refer to files or directories, whether they are sandboxed or not.
8096

8197
* The type parameter `a` describes whether the path is `Rel` or `Abs`.
8298
* The type parameter `b` describes whether the path is `File` or `Dir`.
8399
* The type parameter `s` describes whether the path is `Sandboxed` or `Unsandboxed`.
84100

85-
To ensure type safety, there is no way for users to create a value of
101+
To ensure type safety, there is no way for users to create a value of
86102
this type directly. Instead, helpers should be used, such as `rootDir`,
87103
`currentDir`, `file`, `dir`, `(</>)`, and `parsePath`.
88104

89105
This ADT allows invalid paths (e.g. paths inside files), but there is no
90106
possible way for such paths to be constructed by user-land code. The only
91107
"invalid path" that may be constructed is using the `parentDir'` function, e.g.
92-
`parentDir' rootDir`, or by parsing an equivalent string such as `/../`,
108+
`parentDir' rootDir`, or by parsing an equivalent string such as `/../`,
93109
but such paths are marked as unsandboxed, and may not be rendered to strings
94110
until they are first sandboxed to some directory.
95111

@@ -116,7 +132,7 @@ A type describing a file whose location is absolutely specified.
116132
type RelDir s = Path Rel Dir s
117133
```
118134

119-
A type describing a directory whose location is given relative to some
135+
A type describing a directory whose location is given relative to some
120136
other, unspecified directory (referred to as the "current directory").
121137

122138
#### `AbsDir`
@@ -223,7 +239,7 @@ Creates a path which points to a relative directory of the specified name.
223239
dirName :: forall a s. Path a Dir s -> Maybe DirName
224240
```
225241

226-
Retrieves the name of a directory path. Not all paths have such a name,
242+
Retrieves the name of a directory path. Not all paths have such a name,
227243
for example, the root or current directory.
228244

229245
#### `(</>)`
@@ -252,7 +268,7 @@ file "image" <.> "png"
252268
(<..>) :: forall a b s s'. Path a Dir s -> Path Rel b s' -> Path a b Unsandboxed
253269
```
254270

255-
Ascends into the parent of the specified directory, then descends into
271+
Ascends into the parent of the specified directory, then descends into
256272
the specified path. The result is always unsandboxed because it may escape
257273
its previous sandbox.
258274

@@ -278,9 +294,9 @@ Determines if this path is relatively located.
278294
peel :: forall a b s. Path a b s -> Maybe (Tuple (Path a Dir s) (Either DirName FileName))
279295
```
280296

281-
Peels off the last directory and the terminal file or directory name
282-
from the path. Returns `Nothing` if there is no such pair (for example,
283-
if the last path segment is root directory, current directory, or parent
297+
Peels off the last directory and the terminal file or directory name
298+
from the path. Returns `Nothing` if there is no such pair (for example,
299+
if the last path segment is root directory, current directory, or parent
284300
directory).
285301

286302
#### `maybeDir`
@@ -330,7 +346,7 @@ Returns the depth of the path. This may be negative in some cases, e.g.
330346
parentDir :: forall a b s. Path a b s -> Maybe (Path a Dir s)
331347
```
332348

333-
Attempts to extract out the parent directory of the specified path. If the
349+
Attempts to extract out the parent directory of the specified path. If the
334350
function would have to use a relative path in the return value, the function will
335351
instead return `Nothing`.
336352

@@ -381,7 +397,7 @@ Renames a file path.
381397
renameDir :: forall a s. (DirName -> DirName) -> Path a Dir s -> Path a Dir s
382398
```
383399

384-
Renames a directory path. Note: This is a simple rename of the terminal
400+
Renames a directory path. Note: This is a simple rename of the terminal
385401
directory name, not a "move".
386402

387403
#### `canonicalize`
@@ -412,7 +428,7 @@ unsafePrintPath :: forall a b s. Path a b s -> String
412428
printPath :: forall a b. Path a b Sandboxed -> String
413429
```
414430

415-
Prints a `Path` into its canonical `String` representation. For security
431+
Prints a `Path` into its canonical `String` representation. For security
416432
reasons, the path must be sandboxed before it can be rendered to a string.
417433

418434
#### `printPath'`
@@ -421,8 +437,8 @@ reasons, the path must be sandboxed before it can be rendered to a string.
421437
printPath' :: forall a b. Escaper -> Path a b Sandboxed -> String
422438
```
423439

424-
Prints a `Path` into its canonical `String` representation, using the
425-
specified escaper to escape special characters in path segments. For
440+
Prints a `Path` into its canonical `String` representation, using the
441+
specified escaper to escape special characters in path segments. For
426442
security reasons, the path must be sandboxed before rendering to string.
427443

428444
#### `identicalPath`
@@ -431,8 +447,8 @@ security reasons, the path must be sandboxed before rendering to string.
431447
identicalPath :: forall a a' b b' s s'. Path a b s -> Path a' b' s' -> Boolean
432448
```
433449

434-
Determines if two paths have the exact same representation. Note that
435-
two paths may represent the same path even if they have different
450+
Determines if two paths have the exact same representation. Note that
451+
two paths may represent the same path even if they have different
436452
representations!
437453

438454
#### `relativeTo`
@@ -441,19 +457,19 @@ representations!
441457
relativeTo :: forall a b s s'. Path a b s -> Path a Dir s' -> Maybe (Path Rel b s')
442458
```
443459

444-
Makes one path relative to another reference path, if possible, otherwise
445-
returns `Nothing`. The returned path inherits the sandbox settings of the
460+
Makes one path relative to another reference path, if possible, otherwise
461+
returns `Nothing`. The returned path inherits the sandbox settings of the
446462
reference path.
447463

448-
Note there are some cases this function cannot handle.
464+
Note there are some cases this function cannot handle.
449465

450466
#### `sandbox`
451467

452468
``` purescript
453469
sandbox :: forall a b s. Path a Dir Sandboxed -> Path a b s -> Maybe (Path Rel b Sandboxed)
454470
```
455471

456-
Attempts to sandbox a path relative to some directory. If successful, the sandboxed
472+
Attempts to sandbox a path relative to some directory. If successful, the sandboxed
457473
directory will be returned relative to the sandbox directory (although this can easily
458474
be converted into an absolute path using `</>`).
459475

@@ -475,7 +491,7 @@ parsePath :: forall z. (RelFile Unsandboxed -> z) -> (AbsFile Unsandboxed -> z)
475491
```
476492

477493
Parses a canonical `String` representation of a path into a `Path` value.
478-
Note that in order to be unambiguous, trailing directories should be
494+
Note that in order to be unambiguous, trailing directories should be
479495
marked with a trailing slash character (`'/'`).
480496

481497
#### `parseRelFile`
@@ -521,4 +537,46 @@ instance showPath :: Show (Path a b s)
521537

522538
``` purescript
523539
instance eqPath :: Eq (Path a b s)
540+
```
541+
542+
543+
#### `showFileName`
544+
545+
``` purescript
546+
instance showFileName :: Show FileName
547+
```
548+
549+
550+
#### `eqFileName`
551+
552+
``` purescript
553+
instance eqFileName :: Eq FileName
554+
```
555+
556+
557+
#### `ordFileName`
558+
559+
``` purescript
560+
instance ordFileName :: Ord FileName
561+
```
562+
563+
564+
#### `showDirName`
565+
566+
``` purescript
567+
instance showDirName :: Show DirName
568+
```
569+
570+
571+
#### `eqDirName`
572+
573+
``` purescript
574+
instance eqDirName :: Eq DirName
575+
```
576+
577+
578+
#### `ordDirName`
579+
580+
``` purescript
581+
instance ordDirName :: Ord DirName
524582
```

0 commit comments

Comments
 (0)