ocaml-batteries-team/batteries-included — Issue #190: Make PathGen.PathType.t abstract
Author: toton
Created: 2011-12-13 02:13:56+00:00
State: open

Let me note the issue here, I may be unable to do this myself before 2.0 goes out.
This is breaking change and I hope 2.0 will swallow more API changes.

Current implementation is tied to string list, but this may be far from optimal. If Path.to_string is called frequently for the same path, time is wasted on string concats. I tried to find better implementation, but so far I got no visible speedup for my use cases. I feel the implementation needs some laziness/memoization.

Anyway, if type of the path is abstract, we are no longer tied to this particular implementation.
Although, I have an impression that abstract type may deter newcomers. This is a downside. Hopefully not significant.

The module needs two more constructing functions and an extractor:

```
let absolute = root
let relative = []

type absrel = Absolute | Relative

let components path = match List.rev path with
| rt :: abs when isroot rt -> (Absolute, abs)
| rel -> (Relative, rel)
```
```
val is_relative : t -> bool
val is_absolute : t -> bool

type absrel = Absolute | Relative

val components : t -> (absrel * string list)
(** [components (root/:"a"/:"b"/:"c") = (Absolute, ["a"; "b"; "c"])],
[components (relative/:"a"/:"b"/:"c") = (Relative, ["a"; "b"; "c"])].
*)
```
The additions, of course, need no making `t` abstract.