skip to main content
research-article

A play on regular expressions: functional pearl

Authors Info & Claims
Published:27 September 2010Publication History
Skip Abstract Section

Abstract

Cody, Hazel, and Theo, two experienced Haskell programmers and an expert in automata theory, develop an elegant Haskell program for matching regular expressions: (i) the program is purely functional; (ii) it is overloaded over arbitrary semirings, which not only allows to solve the ordinary matching problem but also supports other applications like computing leftmost longest matchings or the number of matchings, all with a single algorithm; (iii) it is more powerful than other matchers, as it can be used for parsing every context-free language by taking advantage of laziness.

The developed program is based on an old technique to turn regular expressions into finite automata which makes it efficient both in terms of worst-case time and space bounds and actual performance: despite its simplicity, the Haskell implementation can compete with a recently published professional C++ program for the same problem.

Skip Supplemental Material Section

Supplemental Material

icfp-weds-1705-fischer.mov

References

  1. }}C. Allauzen and M. Mohri. A unified construction of the Glushkov, follow, and Antimirov automata. In R. Kralovic and P. Urzyczyn, editors, phMathematical Foundations of Computer Science 2006 (MFCS 2006), Stará Lesná, Slovakia, volume 4162 of Lecture Notes in Computer Science, pages 110--121. Springer, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}P. Caron and M. Flouret. From Glushkov WFAs to rational expressions. In Z. Ésik and Z. Fülöp, editors, Developments in Language Theory, 7th International Conference (DLT 2003), Szeged, Hungary, volume 2710 of Lecture Notes in Computer Science, pages 183--193. Springer, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}M. Droste, W. Kuich, and H. Vogler. Handbook of Weighted Automata. Springer, New York, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}V. M. Glushkov. On a synthesis algorithm for abstract automata. Ukr. Matem. Zhurnal, 12 (2): 147--156, 1960.Google ScholarGoogle ScholarCross RefCross Ref
  5. }}S. A. Greibach. A new normal-form theorem for context-free phrase structure grammars. J. ACM, 12 (1): 42--52, 1965. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}Haskell Wiki. Haskell - regular expressions. http://www.haskell.org/haskellwiki/Regular_expressions.Google ScholarGoogle Scholar
  7. }}P. Hudak, J. Hughes, S. L. Peyton-Jones, and P. Wadler. A history of Haskell: being lazy with class. In Third ACM SIGPLAN History of Programming Languages Conference (HOPL-III), San Diego, California, pages 1--55. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}S. Kleene. Representation of events in nerve nets and finite automata. In C. Shannon and J. McCarthy, editors, Automata Studies, pages 3--42. Princeton University Press, Princeton, N.J., 1956.Google ScholarGoogle Scholar
  9. }}R. McNaughton and H. Yamada. Regular expressions and state graphs for automata. IEEE Transactions on Electronic Computers, 9 (1): 39--47, 1960.Google ScholarGoogle ScholarCross RefCross Ref
  10. }}M. O. Rabin and D. Scott. Finite automata and their decision problems. IBM journal of research and development, 3 (2): 114--125, 1959. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}M. P. Schützenberger. On the definition of a family of automata. Information and Control, 4 (2--3): 245--270, 1961.Google ScholarGoogle Scholar
  12. }}K. Thompson. Programming techniques: Regular expression search algorithm. Commun. ACM, 11 (6): 419--422, 1968. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A play on regular expressions: functional pearl

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      ePub

      View this article in ePub.

      View ePub
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!