[Start regexp introduction. Bryan O'Sullivan **20070608070815 Long delay caused by writing of ghci session recorder. ] { hunk ./en/00book.xml 26 + hunk ./en/Makefile 8 -src-examples = \ +src-examples := \ hunk ./en/Makefile 10 - ch07/glob-to-regexp/GlobWithRegex.hs + ch07/glob-to-regexp/GlobWithRegex.hs \ + ch07/regexp.ghci + +src-ghci := $(filter %.ghci,$(src-examples)) hunk ./en/Makefile 31 -xmlto-opts := --skip-validation +xmlto-opts := --skip-validation --searchpath '$(CURDIR)' hunk ./en/Makefile 99 - cat .stamp-*.hs | sort > all-entities.txt - grep '^ book-entities.txt + cat .stamp-*.ghci .stamp-*.hs | sort > all-entities.txt + grep '^ book-entities.txt hunk ./en/Makefile 113 +vpath %.ghci $(addprefix ../examples/,$(dir $(src-examples))) hunk ./en/Makefile 115 -.stamp-%: % +.stamp-%.hs: %.hs hunk ./en/Makefile 118 +.stamp-%.ghci: %.ghci + ../tools/bin/ghcisession $(CURDIR) $< > $@ + hunk ./en/ch07-globs-and-regexps.xml 39 - referred to as glob patterns, wildcard - patterns, or shell-style patterns. - These patterns have just a few simple rules. + referred to as glob patterns (the term we'll + use), wildcard patterns, or shell-style + patterns. These patterns have just a few simple + rules. hunk ./en/ch07-globs-and-regexps.xml 91 + + While Haskell doesn't provide a glob matching function, it + has excellent regular expression matching facilities. Glob + patterns are nothing more than restricted regular expressions + with slightly different syntax. It's easy to convert glob + patterns into regular expressions, so we'll take that tack + initially. But in order to do so, we must first understand how + to use regular expressions in Haskell. + + + + Regular expressions in Haskell + + In this section, I'll be assuming that you are already + familiar with regular expressions (which I'll abbreviate as + regexps from here on) by way of some other + language, such as Python, Perl, or Java. Rather than introduce + them as something new, I'll be focusing on what's different + about regexp handling in Haskell, compared to imperative + languages. + + The first hurdle to overcome is that Haskell's regexp + library makes heavy use of polymorphism; as a result, many of + its type signatures are difficult to understand. +®exp.ghci:typetwiddle; }