Designing a Paths Julep

Exactly this idea occured to me (except with AbsolutePath and RelativePath types), the issue I had is that I can’t see a way to have this and platform-secific types without multiple inheritence. To elaborate, the problem is that we then have:

<: AbsoluteSystemPath <: RelativeSystemPath
<: PosixPath AbsolutePosixPath RelativePosixPath
<: WindowsPath AbsoluteWindowsPath RelativeWindowsPath

Perhaps one could put absolute/relative-ness in a boolean type parameter? That might work but seems a but awkward to me.

Example (untested) implementation
abstract type SystemPath{isabs} <: PlainPath end

const AbsolutePath <: SystemPath{true}
const RelativePath <: SystemPath{false}

struct PosixPath{isabs} <: SystemPath{isabs}
    path::GenericPlainPath{PosixPath{isabs}}
end

const AbsolutePosixPath = PosixPath{true}
const RelativePosixPath = PosixPath{false}

struct WindowsPath{isabs} <: WindowsPath{isabs}
    path::GenericPlainPath{WindowsPath{isabs}}
end

const AbsoluteWindowsPath = WindowsPath{true}
const RelativeWindowsPath = WindowsPath{false}

My main concern with this design is the amount of potentially unstable path code that would result from it (e.g. parsing a path).

2 Likes