[Haskell-cafe] Text search

Bulat Ziganshin bulatz at HotPOP.com
Mon May 16 10:29:09 EDT 2005

Hello Gracjan,

Monday, May 16, 2005, 4:00:33 PM, you wrote:
GP>  > Unless you have very repetitive data and/or tiny alphabet, it is
GP>  > actually quite efficient, as the expected length of prefixes that need
GP>  > to be checked before a mismatch can be determined is small.
GP>  >
GP>  > At least, I was unable to beat it with my (feeble attempts at) BM or
GP>  > KMP implementations.

if you really need KMP, you can find it at http://haskell.org/hawiki/RunTimeCompilation

> find (isSuffixOf "needle") (inits "haystack")

find (isPrefixOf "needle") (tails "haystack")

if you need an index - add it with zip:

find (isPrefixOf "needle".snd) (zip [0..] (tails "haystack"))

Best regards,
 Bulat                            mailto:bulatz at HotPOP.com

More information about the Haskell-Cafe mailing list