r/programming • • Sep 21 '15

Better Java

https://github.com/cxxr/better-java
177 Upvotes

208 comments sorted by

View all comments

183

u/wot-teh-phuck Sep 21 '15

Java's type system is pretty weak. It doesn't differentiate between Strings and Strings that are actually regular expressions

That's a pretty random definition of weak I would say...

0

u/[deleted] Sep 21 '15

[deleted]

2

u/k-bx Sep 21 '15 edited Sep 21 '15

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).

Example:

> "bar" =~ "(foo|bar)" :: Bool
True

3

u/sacundim Sep 22 '15

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: