Optimising words

Neil Mitchell ndmitchell at gmail.com
Mon Jul 9 19:06:10 EDT 2007


Actually, you can go slightly better:

words s     = case dropWhile isSpace s of
                  [] -> []
                  (s:ss) -> (s:w) : drop1 sss
                          (w, sss) = break isSpace ss

                          drop1 [] = []
                          drop1 (x:xs) = words xs

Although a good optimising compiler may make this last leap all on its own.

> To really convince yourself and everyone else you could compare it
> against the spec, for both total and partial values.

I'm pretty convinced that I applied reasoning rules at each stage. If
you have a proof, testing is irrelevant :-)

I've already modified the Yhc base library with this optimisation, and
done some basic testing, and nothing broke.



More information about the Libraries mailing list