I had the idea that literals for paths and URIs could be added to Scala. I don’t expect that that will ever happen. Well, who knows?
So what I imaging is that a path literal e.g. “/home/myUser/” would become an instance of java.nio.file.Path and a URI like “https://users.scala-lang.org/” would become an instance of a proper URI type (not sure about java.net.URI).
The target is to ease and short IO code, while still staying type safe. Personally I would not hard code many paths and URIs in professional software but, outsource them to a config file or something else. Still I think those literals could be useful for scripting and rapid prototyping.
I never wrote a compiler so I can’t judge if the parsing of a URI inside Scala code would be problematic. What I see is that both contain dots and colons which could possibly make thing difficult.
Maybe it’s easier with the paths where I can think of that paths must start with
/ for absolute paths and with
./ for relative paths. Unfortunately paths on windows look different as they use backslash for separation and IIRC can start with “c:/” and similar things.
What is your opinion? Would those literals be useful? Would the implementation be problematic?
P.S.: I never used macros. Can macros only use known scala symbols / constructs or could they rewrite a literal to code that instantiates e.g. java.nio.Path?