[Haskell-cafe] Text search

Graham Klyne GK at ninebynine.org
Mon May 16 05:57:36 EDT 2005

At 10:27 16/05/05 +0200, Gracjan Polak wrote:

>Simple question: I need a function that matches string in another string. 
>Something like:
>find (isSuffixOf "needle") (inits "haystack")
>This one is beautiful, but not very practical. Could anybody point me to 
>some haskell library that does some searching, using KMP for example?

import List
foo = isPrefixOf (reverse "needle") (reverse "haystack with needle")
bar = isPrefixOf (reverse "needle") (reverse "haystack with pins")

Seems to work.  And (by inspection) is linear in size of haystack.


Graham Klyne
For email:

More information about the Haskell-Cafe mailing list