[darcs-devel] [issue1717] Confusing behaviour when "No newline at end of file"

Ganesh Sittampalam bugs at darcs.net
Mon Dec 14 10:28:15 UTC 2009


Ganesh Sittampalam <ganesh at earth.li> added the comment:

I don't think the assumption is that there's a single ^J - if that were the
case, then it wouldn't report a diff between an empty file and one containing a
single ^J, but it does.

The issue is more that it models every file as a non-empty list of strings, with
the invariant

    file_contents = Data.List.intercalate "\n" file_lines

(where intercalate sticks the separator between each element but not at the end)

So the empty file corresponds to [""], a file with a newline at the end
corresponds to [..., ""], and a file doesn't have an empty string at the end of
the list.

I think this model is necessary. The alternative I first thought of was

    file_contents = unlines file_lines

(where unlines adds a newline after every single line).

But this simply can't represent files without trailing newlines (and indeed,
unlines . lines is not the identity:

    Prelude> unlines (lines "wibble")
    "wibble\n"

So I don't see any obvious alternative to the current behaviour.

----------
nosy: +ganesh

__________________________________
Darcs bug tracker <bugs at darcs.net>
<http://bugs.darcs.net/issue1717>
__________________________________


More information about the darcs-devel mailing list