Legend:
Library
Module
Module type
Parameter
Class
Class type
A path describes a path in the file system. It is only a description, which does not produce any ad-hoc verification. It is therefore unfortunately possible to describe inconsistent paths (however, the expression of inconsistent paths is captured by the YOCaml core executable).
The implementation of paths is clearly not the most optimised, it would be possible to do much more efficiently (for example, build the list in reverse or use a difference list) but we assume that this is not a catastrophic operation as file paths are generally short.
TODO: The aim of this implementation is to find an API that is easy to extend to capture the different uses in YOCaml. Once this API has stabilised, we can think about a less naive implementation.
Types
The different types used to describe a path. These are essentially aliases for strings and lists of strings.
type fragment = string
A fragment is an element of a path. For example, in the following path: "foo/bar/baz", fragments are : "foo", "bar" and "baz".
type t
A path (Path.t) is just a line of fragments. Building paths that are "correct by construction" is an attractive idea, but it involves working with more complicated types. We prefer to use Effect interpretation to deal with incorrect path errors.
add_extension ext path add the extension ext to the last fragment of the path. If the path or the extension is empty, it keep it without change. .ext is treated like ext.
change_extension ext path replace (or add) ext to the given path. The function follows the same scheme of add_extension. If the extension is invalid, it will returns the path with the extension removed.