How does one print quotes in haskell? I would think it is

putStrLn "\"" 

but it is not :( I know it's a simple question, but I can't find it anywhere.

To clarify, the result should be simply: " Thanks

有帮助吗?

解决方案

If you just want to print a single double quote, you can use putChar, like so:

putChar '"'

Keep in mind that this will not append a newline or anything else like that. If you want to print a quote with a newline, the code you have supplied should be correct.

putStrLn "\""

should work. The reason for the backslash is that double quotes are used to end strings, so we need to tell the compiler to treat this particular double quote specially – we do that with a backslash.

The combination of a backslash and a character is usually called an "escape sequence" – we have others like \n for a newline, \t for a tab character and \\ for an actual backslash. This of course means that you can print a double quote followed by a newline by combining two putChars into

putChar '"' >> putChar '\n'

where >> is the operator to chain two printing operations together. However, doing this is a little weird when you can just do putStrLn "\"" instead.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top