[Haskell-cafe] Missing join and split

Evan Laforge qdunkan at gmail.com
Fri Dec 28 18:13:59 EST 2007

> Would not it be interesting and useful (but not really efficient) to
> have patterns something like:
> foo :: Eq a => a -> ...
> foo (_{4}'b') = ...
> which would match a list with four elements ending with an element 'b'. Or:
> foo (_+';'_+';'_) = ...

Maybe you could use view patterns?

foo (regex "(.*);(.*);(.*)") -> [c1, c2, c3] = ...

> OK, maybe guards are not the proper place to implement this as would
> add a possibility to make a really messy Haskell programs. But
> extending regular expressions to work on any list of elements with
> type implementing Eq would be realy powerfull. And then we could use
> split in many other than just text processing contexts.
> Of course, the problem in both cases is implementing something like
> regular expressions efficiently, especially on lists, but this is why
> there are smart people around. :-)

Parser combinators basically provide generalized regexes, and they all
take lists of arbitrary tokens rather than just Chars.  I've written a
simple combinator library before that dispenses with all the monadic
goodness in favor of a group combinator and returning [Either [tok]
[tok]], which sort of gives parsers a simpler regexy flavor (Left is
"out of group chunk" and Right is "in group chunk").

foo (match (group any `sepBy` char ';') -> [c1, c2, c3]) = ...

More information about the Haskell-Cafe mailing list