linesPS is not analagous to lines

Simon Marlow
Mon, 14 Apr 2003 12:22:21 +0100

[ moving to ]

> I've just switched my code to use PackedStrings rather than=20
> Strings for
> file contents, and ran into what appears to be a bug in the
> Data.PackedString module in ghc 5.04.3.
> unlines is the inverse of lines, since lines converts empty lines into
> empty strings.  linesPS, however, ignores empty lines.  :( =20
> It seems like
> it would be a good idea to either fix this (which might not=20
> be a good idea,
> if existing code depends on its current behavior), or add a=20
> note in the
> documentation that it isn't analagous to lines, so that other=20
> people won't
> make the same mistake based on its similar name.

Indeed, that looks like a bug.

linePS is defined as (splitPS '\n'), and it appears that splitPS strips =
out empty substring matches.  wordsPS uses this property, so
that it works analogously to List.words (which doesn't return any empty =

However, the comment in the code says that

  joinPS (packString [x]) (splitPS x ls) =3D ls

which isn't true if splitPS removes empty substrings.  It therefore =
looks like splitPS is wrong to drop empty substrings, and
wordsPS should explicitly filter them out.  I'll make this change unless =
anyone complains.

Also, I just noticed that joinPS is missing from Data.PackedString, for =
no apparent reason.