[Haskell-cafe] wordsBy in the base libraries?

Yitzchak Gale gale at sefer.org
Mon Oct 22 06:26:46 EDT 2007


Maxime Henrion wrote:
> This version takes care of avoiding a redundant character check

It still has several redundant checks:

s'' is known to begin with space if it is non-empty,
but that is checked again in the recursive call
of wordsBy. In fact, break already checked whether
s'' is empty, but wordsBy checks that again, too.

Also - the pattern match in the case checks
whether its list is empty, but that was already
checked by dropWhile.

If you want to guarantee that level of optimization,
you probably have to inline everything by hand
and not use any library functions at all. I wonder how
much of that is already done by the compiler,
though.

-Yitz


More information about the Haskell-Cafe mailing list