string literals and haskell'

I've just been annoyed with errors ghc reports when I use a string literal such as ":\/:" (which is a contructor in darcs). Of course, it wants ":\\/:", but I'd rather type the former. Is there any reason why the language couldn't be modified (e.g. in haskell') to make the former legal? i.e. to treat string literals with '\\' followed by a character that doesn't describe an escape as a literal backslash? It makes the rules a bit more complicated, but doesn't modify the meaning of any currently-legal code, and removes a potential error. -- David Roundy Department of Physics Oregon State University

Hi
I can see problems with this. This comes up when typing windows file path's:
"C:\path to my\directory\boo"
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:
@":\/"
In a @" string, there are no escape characters, except for "" which
means ". There are various other quoting mechanisms available - but
all have the problem of being yet another thing to learn.
Thanks
Neil
On 10/22/07, David Roundy
I've just been annoyed with errors ghc reports when I use a string literal such as ":\/:" (which is a contructor in darcs). Of course, it wants ":\\/:", but I'd rather type the former. Is there any reason why the language couldn't be modified (e.g. in haskell') to make the former legal? i.e. to treat string literals with '\\' followed by a character that doesn't describe an escape as a literal backslash? It makes the rules a bit more complicated, but doesn't modify the meaning of any currently-legal code, and removes a potential error. -- David Roundy Department of Physics Oregon State University _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, 2007-10-22 at 17:12 +0100, Neil Mitchell wrote:
Hi
I can see problems with this. This comes up when typing windows file path's:
"C:\path to my\directory\boo"
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:
@":\/"
In a @" string, there are no escape characters, except for "" which means ". There are various other quoting mechanisms available - but all have the problem of being yet another thing to learn.
I really like this in C# and wouldn't mind something similar in a future Haskell.

On 10/22/07, Neil Mitchell
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 newlines. EOS 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 EOS 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 string. EOS My two cents - I haven't found another language that handles heredocs as nicely as Ruby does. Justin

2007/10/23, Justin Bailey
My two cents - I haven't found another language that handles heredocs as nicely as Ruby does.
Perl Heredocs do the same things and predates Ruby's (at least they do all you described and a bit more). But what would be really nice is a way to write regex without \\ everywhere, as of now this is the single thing that makes regex in Haskell less pleasant than in a language like Perl (which has built-in support for them, but just to be able to ignore all escape codes would be really useful). -- Jedaï
participants (5)
-
Chaddaï Fouché
-
David Roundy
-
Derek Elkins
-
Justin Bailey
-
Neil Mitchell