[Haskell-cafe] cutting long strings into lines

Udo Stenzel u.stenzel at web.de
Sat Sep 30 14:51:40 EDT 2006

Matthias Fischmann wrote:
> although this wasn't the original problem, i like it, too :).  but now
> i am stuck in finding an optimal implementation for lines.

Isn't the obvious one good enough?

lines [] = []
lines s = go s
    go [] = [[]]
    go ('\n':s) = [] : lines s
    go (c:s) = let (l:ls) = go s in (c:l):ls

"Money can't buy friends, but it can get you a better class of enemy."
	-- Spike Milligan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20060930/097668c7/attachment-0001.bin

More information about the Haskell-Cafe mailing list