Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: should I bother compiling regular expressions?

Tags:

regex

haskell

My impulse is to say yes, especially if I'm using the same regex in multiple code locations, but this article indicates that the library will cache the compilation for me (which I'm not even sure how it would do):

There’s normally no need to compile regular expression patterns. A pattern will be compiled the first time it’s used, and your Haskell runtime should memoise the compiled representation for you.

like image 418
rampion Avatar asked Mar 11 '12 04:03

rampion


1 Answers

If you reuse a regular expression then it is worthwhile to use the RegexMaker type class to define the "compiled" regular expression. It has the ability to take additional options and the ability to report compilation failure in your choice of Monad.

To use the "compiled" form you can use 'match' or 'matchM' from RegexLike which gives you the equivalent to =~ or ==~ operators.

like image 134
Chris Kuklewicz Avatar answered Sep 21 '22 21:09

Chris Kuklewicz