std/path
Lexical POSIX paths. Only / separates names; no function consults the
filesystem, a current directory, or a platform’s drive conventions.
Unicode, NUL, backslashes, and percent escapes are ordinary characters.
RelativeError
Why a lexical relative path cannot be found.
RelativeError = DifferentRoots | UnknownParent clean
Removes empty and dot segments and resolves lexical parents. Empty relative
paths become ., and parents cannot climb above an absolute root.
clean = (path : String) -> String { join
Joins nonempty pieces with /, then cleans. All-empty input gives "".
A slash at the start of a later piece does not reset earlier pieces.
join = (parts : List(String)) -> String { split
Cuts raw input after its last slash, keeping that slash in the first part.
split = (path : String) -> (String, String) { base
The final raw name after stripping trailing slashes. Empty input gives .,
and an all-slash input gives /. Dots are not resolved.
base = (path : String) -> String { dir
The cleaned directory part of split.
dir = (path : String) -> String { extension
The suffix from the last dot in the final raw segment. A dotfile’s leading dot counts, and a trailing slash gives an empty extension.
extension = (path : String) -> String { is_absolute
Tests only for a leading slash.
is_absolute = (path : String) -> Bool { relative
A lexical route from one location to another. Different roots and unmatched parents in the base are errors. Neither location is implicitly a file.
relative = (from : String, to : String) -> Result(String, RelativeError) {