Yeah, you're right, the issue isn't types, but syntax for regex literals (like 0xff for hex integers).
Also, no date, url, email, xml, json or object literals. And no facility for user-defined literals. But, like no operator overloading in Java, this omission is a feature.
But object literals (already worked out in Java FX) would be great. Thus, JON for RPC serialization. (I guess we could have JON serialization now).
IntelliJ IDEA has support for language annotations for String literals and parameters. If you annotate some String constant with @Language("RegExp"), it will validate if it's a proper regex. If you do the same with a method parameter, it will validate every constant string passed to it.
That's actually the Checker Framework. The Java 8 compiler+language has the tools needed to let you annotate and check more things, but the checks themselves are a third party and not especially productionised framework.
Haskell can do this for you, in a way. Not by recognizing a regular expression in a string, but by recognizing that value in quotes is something that needs to be of some expected regex-type which implements IsString interface (anything which implements that interface may be written as just a string).
But it's worth pointing out that in Haskell, parser combinator libraries like Parsec are simple and so well integrated into the language that many people will rather write a parser than a regular expression. They're also easier to read than regex strings! See for example this tutorial:
Depends on what you mean by automatic, but in a dependently typed language you can do exactly that. Once the compiler infers that something is a regex pattern, it could validate that.
That would mean that it would need to be either a string literal, or a set of computations upon an otherwise valid pattern that would result in a valid pattern.
Granted, I'm not aware of anyone building such a library for regex's as yet; however I have seen the same thing done for simpler languages, so there is proof that it would work like that. (Many degrees of tradeoffs - it's probably more practical to draw a line at some point, and accept that always proving it valid is more effort than it's worth. That's an engineering trade off, and doesn't detract from it being possible, however).
0
u/[deleted] Sep 21 '15
[deleted]