[Haskell-cafe] string literals and haskell'

Justin Bailey jgbailey at gmail.com
Tue Oct 23 14:31:51 EDT 2007

On 10/22/07, Neil Mitchell <ndmitchell at gmail.com> wrote:
> If this now reports no errors, who wants to guess which come up as
> escape codes, and which don't. The way other languages like C# have
> dealt with this is by introducing a new type of quoted string:
> @":\/"

The C# implementation is really annoying, because quotes appear in strings
so often. Whenever I wanted to use that facility its because I have some
inline XML, and I have to double up all the quotes after pasting it in.

I like the idea of 'heredocs' from Ruby, PHP and others. Using Ruby, I can
specify a string fairly easily:

  puts <<-EOS
This is a long string
that will print as formatted,
  including spaces, "quotes" and

Note that quotes and such don't need to be escaped. What's really sweet is
Ruby treats that as a string in-place, so if puts took more arguments they
just come after the heredoc:

 puts <<-EOS, "foo", true, 1
My string which
doesn't interfere with the arguments above

Of course, because strings are just another object in Ruby, you can call
methods on the string constructed:

  puts <<-EOS.length
This will print
the length of the

My two cents - I haven't found another language that handles heredocs as
nicely as Ruby does.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071023/8989b361/attachment.htm

More information about the Haskell-Cafe mailing list