Parser Combinators beat Regexes
great post on parser combinators - haskell specifically is a language with very little support for regex within its ecosystem due to the language lending itself to monadic parser combinators. This is a great intro to the semantics of it, shame it doesn't mention the other general benefits to parsing over regex such as performance and dx https://entropicthoughts.com/parser-combinators-beat-regexes
1mo
55
This is mostly a Haskell issue, as the language does not compile regex's into byte code or DFA/NFA like most modern languages... No surprise that doing this manually is faster than a regex in that context.
Regex is slower than parsing in every language? Haskell's design just lends itself to providing a really nice dx/solution for them
The performance of compiled Regex is roughly the same as parsing for tasks of the same complexity. For complex tasks compiled Regex are often faster as the compiler is more likely to write optimized structures than developers.
Yes you can write faster solutions by hand, however most people don't.
yep, people don't, and probably shouldn't d2d iin most languages, which swings back to the developer experience and semantics of monadic parser combinator libs discussed in the blog post - In a lot of languages it's almost always easier to regex your way out of something (especially since in a lot of normal world use cases in web world especially are pretty mediocre check-if-this-is-an-email type use cases), but hs & it's libs make building and combining parsers so easy that it almost makes one of the most common denominators of other language obsolete, which I think is pretty cool
[deleted]