turtle icon indicating copy to clipboard operation
turtle copied to clipboard

output always appends a newline

Open Profpatsch opened this issue 10 years ago • 3 comments

output "test" $ pure "foo"

gives a file with "foo\n" whereas

echo -n "foo" > test

gives a file with "foo", > doesn’t change the input.

This may be (was actually. :)) source of confusion. Of course it can be migitated by using Text.writeFile.

Profpatsch avatar May 01 '15 11:05 Profpatsch

Yeah, this is intentional. The convention of the turtle library is that if you have a stream of Text, then each element represents lines, which is why when you write it out turtle adds newlines. I decided to sacrifice generality for convenience. If you want a (much) more general API then you may want to check out the pipes/pipes-group/pipes-text ecosystem which lets you group things along arbitrary chunk boundaries.

turtle does not even expose a way to write a line without a trailing newline anywhere in the API.

My recommendation is just to import an external function (like putStr or writeFile). Think of turtle more as a stepping stone to introduce beginners to the rest of the Haskell ecosystem rather than a comprehensive library.

Gabriella439 avatar May 01 '15 16:05 Gabriella439

Okay. I wasn’t aware of that. Maybe that is missing somewhere in the documentation?

Think of turtle more as a stepping stone to introduce beginners to the rest of the Haskell ecosystem rather than a comprehensive library.

As a regular Haskell user I still find it immensely useful.

Profpatsch avatar May 01 '15 17:05 Profpatsch

Alright, I'll add something to that effect in either the main documentation or the tutorial (or both)

Gabriella439 avatar May 01 '15 17:05 Gabriella439