commercialhaskell / path

Typed filepath
Other
122 stars 45 forks source link

Idea/suggestion: Path aliases #151

Closed Martinsos closed 4 years ago

Martinsos commented 4 years ago

Hi, thanks for this great library! I was just starting to write my own solution when I realized this exists.

One thing I noticed is that when I want to specify the type of Path in my code, I have following options:

  1. import Path and then myPath :: Path Rel File.
  2. import qualified Path as P and then myPath :: P.Path P.Rel P.File
  3. import Path (Path, Rel, Abs, File, Dir) and then myPath :: Path Rel File and so on.

Problem with having Path, Rel, Abs, File, Dir directly as names in the scope for me is that these are really short names and might likely come in conflict with some of my own datatypes (in my case, I had data type File). On the other hand, having them qualified and then prefixing them all with P. or smth similar doesn't look nice.

What I did is define module Path.Aliases which has

type RelFile = Path Rel File
type AbsFile = Path Abs File
type RelDir = Path Rel Dir
type AbsDir = Path Abs Dir

and now if I import it as import qualified Path.Aliases as Path I can do :: Path.RelFile and similar.

Would it make sense to offer smth like this as part of the Path package? I am aware there is a high change you already thought about this, but I could not phantom a reason against it (I am somewhat new to Haskell though), so I thought I should ask.

Martinsos commented 4 years ago

Closing this -> as codebase evolved, I actually found that rarely there is a conflict with other types, so I don't think any more that this brings a lot of value.