[Haskell-cafe] Re: Missing join and split

ChrisK haskell at list.mightyreason.com
Fri Dec 28 12:26:11 EST 2007

Lihn, Steve wrote:
> Programmer with perl background would think split like:
>   <list of string> = split <regex> <original string>
> Since regex is involved, it is specific to (Byte)String, not a generic
> list. Also it appears one would need help from Text.Regex(.PCRE) to do
> that.
>>     intercalate a (split a xs) = a
> This identity rule does not hold for perl's join/split if regex is used.
> Steve  

Well, libpcre does not have a split function.

One can already write a split that uses the high level Regex API.  The only
reason you might want to dig into regex-pcre's Text.Regex.PCRE would be if it
would help efficiency.

Specifically, regex-base defines a RegexContext instance which is:

( RegexLike a b => RegexContext a b (b, b, b) ) : The text before the match, the
text of the match, the text after the match

So you can iteratively generate the pieces that split returns.


More information about the Haskell-Cafe mailing list