Hi all, I've just released string-qq 0.0.2 to Hackage: http://hackage.haskell.org/package/string-qq The main interface is the "s" quasi-quoter: foo :: IsString a => a foo = [s| This is a multi-line string! |] It allows simple multi-line strings of any IsString type (Text, String, ByteString, etc), with no interpolation at all, except that the leading newline is trimmed and "\r\n" sequences are converted to "\n". It's compatible with both GHC6 and GHC7; for GHC6, write [$s|…|] instead of [s|…|]. Suggestions and feedback are most welcome. :-) Cheers, Audrey
Hi Audrey, are you aware that Haskell already supports multi-line strings? foo = "This is a\ \multi-line\ \string!" See Section 2.6 of http://haskell.org/onlinereport/lexemes.html Regards, Jean On 25.06.11 22:55, 唐鳳 wrote:
Hi all,
I've just released string-qq 0.0.2 to Hackage:
http://hackage.haskell.org/package/string-qq
The main interface is the "s" quasi-quoter:
foo :: IsString a => a foo = [s| This is a multi-line string! |]
It allows simple multi-line strings of any IsString type (Text, String, ByteString, etc), with no interpolation at all, except that the leading newline is trimmed and "\r\n" sequences are converted to "\n".
It's compatible with both GHC6 and GHC7; for GHC6, write [$s|…|] instead of [s|…|].
Suggestions and feedback are most welcome. :-)
Cheers, Audrey
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Jean-Marie Gaillourdet blog: gaillourdet.net {email, xmpp, jabber, ichat, gimix, gtalk}: jmg@gaillourdet.net
2011/6/28 Jean-Marie Gaillourdet <jmg@gaillourdet.net>:
Hi Audrey,
are you aware that Haskell already supports multi-line strings?
foo = "This is a\ \multi-line\ \string!"
See Section 2.6 of http://haskell.org/onlinereport/lexemes.html
I've used this approach for multi-line strings; note first of all that to make the examples equivalent you would need to add '\n' twice to your definition of foo. However, even without that it's rather annoying to use and can be difficult to typeset correctly (though that admittedly could be due to the indentation support in haskell-mode not being up to par as it refuses to indent subsequent lines properly after the String). Another alternative would be: foo = unlines [ "This is a" , "multi-line" , "string!" ] Though it too can be a bit cumbersome.
Regards, Jean
On 25.06.11 22:55, 唐鳳 wrote:
Hi all,
I've just released string-qq 0.0.2 to Hackage:
http://hackage.haskell.org/package/string-qq
The main interface is the "s" quasi-quoter:
foo :: IsString a => a foo = [s| This is a multi-line string! |]
It allows simple multi-line strings of any IsString type (Text, String, ByteString, etc), with no interpolation at all, except that the leading newline is trimmed and "\r\n" sequences are converted to "\n".
It's compatible with both GHC6 and GHC7; for GHC6, write [$s|…|] instead of [s|…|].
Suggestions and feedback are most welcome. :-)
Cheers, Audrey
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Jean-Marie Gaillourdet
blog: gaillourdet.net {email, xmpp, jabber, ichat, gimix, gtalk}: jmg@gaillourdet.net
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com
Jean-Marie Gaillourdet 於 2011/6/28 下午4:57 寫道:
Hi Audrey,
are you aware that Haskell already supports multi-line strings?
foo = "This is a\ \multi-line\ \string!"
Hi Jean-Marie, Yeah, I am aware of that, I wrote a 381-lines multi-lines strings once… :-) https://github.com/audreyt/Pugs.hs/blob/master/Pugs/src/Pugs/Prim.hs#L1863 though as Ivan++ remarked, the extra "\n" is quite cumbersome, and so string-qq just makes it slightly easier to copy-paste multi-line string sections. Cheers, Audrey
Part of the dominance of scripting languages is clean support for heredocs. So much of every arena of life comes down to getting "It's not about me!" I love Haskell but it doesn't get this. Imagine a document that's nominally Haskell, but about 80% some other language such as TeX (e.g. code for a self-generating textbook). Anything short of "these lines belong to the other language, with not a single intervening character in the way" simply doesn't work. So, yes, Haskell supports multi-line strings, but not heredocs, a subtle but crucial syntactic distinction. Restated, one can cut and paste many entire lines of foreign code into a heredoc, with no worries about conversion. Heredocs should be part of the base spec of any credible language, with the requirement "Can the language completely disappear behind another language, in the source file?" As I said, the key issue is getting "It's not about me!" On Jun 28, 2011, at 1:57 AM, Jean-Marie Gaillourdet wrote:
Hi Audrey,
are you aware that Haskell already supports multi-line strings?
foo = "This is a\ \multi-line\ \string!"
See Section 2.6 of http://haskell.org/onlinereport/lexemes.html
Regards, Jean
What about Literate Haskell then? People write a lot of LH blog posts, so it would seem to be quite flexible. Best regards, Krzysztof Skrzętnicki On Tue, Jun 28, 2011 at 16:13, Dave Bayer <bayer@cpw.math.columbia.edu>wrote:
Part of the dominance of scripting languages is clean support for heredocs. So much of every arena of life comes down to getting "It's not about me!" I love Haskell but it doesn't get this. Imagine a document that's nominally Haskell, but about 80% some other language such as TeX (e.g. code for a self-generating textbook). Anything short of "these lines belong to the other language, with not a single intervening character in the way" simply doesn't work. So, yes, Haskell supports multi-line strings, but not heredocs, a subtle but crucial syntactic distinction. Restated, one can cut and paste many entire lines of foreign code into a heredoc, with no worries about conversion.
Heredocs should be part of the base spec of any credible language, with the requirement "Can the language completely disappear behind another language, in the source file?" As I said, the key issue is getting "It's not about me!"
On Jun 28, 2011, at 1:57 AM, Jean-Marie Gaillourdet wrote:
Hi Audrey,
are you aware that Haskell already supports multi-line strings?
foo = "This is a\ \multi-line\ \string!"
See Section 2.6 of http://haskell.org/onlinereport/lexemes.html
Regards, Jean
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
On 06/28/2011 08:25 PM, Krzysztof Skrzętnicki wrote:
What about Literate Haskell then? People write a lot of LH blog posts, so it would seem to be quite flexible.
IMHO, these are different tasks. * "Embed Haskell into some other language" is solved by Literate Haskell * "Embed some other language into Haskell" is solved by heredocs Btw., does TH parse this correctly? (If I was TH, I would not):
myPHPCode = [s| <?php $description = "Use the quasiquoter like this: [s|some text|]"; print $description."\n"; ?> |]
(the tricky part is "|]" occurring in the quoted text) Can we escape it? -- Steffen
Best regards, Krzysztof Skrzętnicki
On Tue, Jun 28, 2011 at 16:13, Dave Bayer <bayer@cpw.math.columbia.edu <mailto:bayer@cpw.math.columbia.edu>> wrote:
Part of the dominance of scripting languages is clean support for heredocs. So much of every arena of life comes down to getting "It's not about me!" I love Haskell but it doesn't get this. Imagine a document that's nominally Haskell, but about 80% some other language such as TeX (e.g. code for a self-generating textbook). Anything short of "these lines belong to the other language, with not a single intervening character in the way" simply doesn't work. So, yes, Haskell supports multi-line strings, but not heredocs, a subtle but crucial syntactic distinction. Restated, one can cut and paste many entire lines of foreign code into a heredoc, with no worries about conversion.
Heredocs should be part of the base spec of any credible language, with the requirement "Can the language completely disappear behind another language, in the source file?" As I said, the key issue is getting "It's not about me!"
On Jun 28, 2011, at 1:57 AM, Jean-Marie Gaillourdet wrote:
> Hi Audrey, > > are you aware that Haskell already supports multi-line strings? > > foo = "This is a\ > \multi-line\ > \string!" > > See Section 2.6 of http://haskell.org/onlinereport/lexemes.html > > Regards, > Jean
_______________________________________________ Haskell mailing list Haskell@haskell.org <mailto:Haskell@haskell.org> http://www.haskell.org/mailman/listinfo/haskell
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
On Jun 28, 2011, at 2:34 PM, Steffen Schuldenzucker wrote:
On 06/28/2011 08:25 PM, Krzysztof Skrzętnicki wrote:
What about Literate Haskell then? People write a lot of LH blog posts, so it would seem to be quite flexible.
IMHO, these are different tasks.
* "Embed Haskell into some other language" is solved by Literate Haskell
* "Embed some other language into Haskell" is solved by heredocs
Nice pairing. I wrote my own literate preprocessor, which GHC gracefully accepts, to accomplish both of these tasks. I use "comments are flush, code is indented" to get rid of the literate Haskell bird tracks, which look like a 1980's email program having a psychotic break. And I support plain and interpolated (EOF or "EOF") heredocs. I've been meaning to upload this literate preprocessor to Cabal. * Comment symbols are an intrusion in plain Haskell * Bird tracks are an intrusion in literate haskell. With a decent syntax-coloring editor, one needs neither. I've always liked the sparest possible look to code. Yes, when I coded in Lisp I also wrote a preprocessor to get rid of most of the parentheses. There are as many such systems as monad tutorials; mine had the distinction that I actually used it. ;-)
Steffen Schuldenzucker wrote:
* "Embed Haskell into some other language" is solved by Literate Haskell * "Embed some other language into Haskell" is solved by heredocs
Dave Bayer wrote:
Nice pairing. I wrote my own literate preprocessor, which GHC gracefully accepts, to accomplish both of these tasks. I use "comments are flush, code is indented" to get rid of the literate Haskell bird tracks... * Comment symbols are an intrusion in plain Haskell * Bird tracks are an intrusion in literate haskell. With a decent syntax-coloring editor, one needs neither.
I think the conclusion we can reach from this thread is that there are many different use cases and many different coding styles. I like bird tracks in certain situations (admittedly not too many), I like the \begin{code} syntax in other situations, and in yet other situations (most actually) I like comment symbols. (Yes, I do use a good syntax-coloring editor.) Sometimes I would prefer standard Haskell multi-line strings, and other times I would prefer Audrey's quasiquoter. If you have a different quasiquoter that you think others might like, please do upload it to Hackage. GHC's new lightweight quasiquoters provide a nice mechanism for easily inventing whatever style you like best. It's also good to know that there are built-in standards, for maximum universal readability. Regards, Yitz
Steffen Schuldenzucker wrote:
Btw., does TH parse this correctly? (If I was TH, I would not):
myPHPCode = [s| <?php $description = "Use the quasiquoter like this: [s|some text|]"; print $description."\n"; ?> |]
(the tricky part is "|]" occurring in the quoted text)
Can we escape it?
Yes, like this: myPHPCode = [s| <?php $description = "Use the quasiquoter like this: [s|some text|]++"|]"++[s|"; print $description."\n"; ?> |] It's a good thing I'm not the one who wrote this quasiquoter. I would have built in a special exception that rejects any string containing "<?php". Regards, Yitz
2011/6/28 Steffen Schuldenzucker <sschuldenzucker@uni-bonn.de>:
Btw., does TH parse this correctly? (If I was TH, I would not):
myPHPCode = [s| <?php $description = "Use the quasiquoter like this: [s|some text|]"; print $description."\n"; ?> |]
(the tricky part is "|]" occurring in the quoted text)
Can we escape it?
-- Steffen
I once spent some time and energy making [foo| bar baz |\] quux |] do the right thing for a quasiquoter I implemented, only to discover that GHC already supports [foo| bar baz \|] quux |]. So yes, you can escape it.
Ben Millwood wrote:
I once spent some time and energy making [foo| bar baz |\] quux |] do the right thing for a quasiquoter I implemented, only to discover that GHC already supports [foo| bar baz \|] quux |]. So yes, you can escape it.
Wow, that actually works. That is very surprising, counter-intuitive, and undocumented. Quasi-quotation is supposed to be a mechanism by which you can define your own compile-time syntax. One would expect GHC to stay out of the way as much as possible. People who need some way to quote "|]" can define their own syntax for that. And if that really is intended to be a supported feature, you would certainly think it important enough to warrant a mention in the GHC docs. So even if this works, I wouldn't rely on it until we get confirmation from the GHC team that it is indeed a supported a feature and won't go away in some future version of GHC. -Yitz
On Tue, 28 Jun 2011 07:13:19 -0700 Dave Bayer <bayer@cpw.math.columbia.edu> wrote:
Part of the dominance of scripting languages is clean support for heredocs. So much of every arena of life comes down to getting "It's not about me!" I love Haskell but it doesn't get this. Imagine a document that's nominally Haskell, but about 80% some other language such as TeX (e.g. code for a self-generating textbook). Anything short of "these lines belong to the other language, with not a single intervening character in the way" simply doesn't work. So, yes, Haskell supports multi-line strings, but not heredocs, a subtle but crucial syntactic distinction. Restated, one can cut and paste many entire lines of foreign code into a heredoc, with no worries about conversion.
Heredocs should be part of the base spec of any credible language, with the requirement "Can the language completely disappear behind another language, in the source file?" As I said, the key issue is getting "It's not about me!"
On Jun 28, 2011, at 1:57 AM, Jean-Marie Gaillourdet wrote:
Hi Audrey,
are you aware that Haskell already supports multi-line strings?
foo = "This is a\ \multi-line\ \string!"
See Section 2.6 of http://haskell.org/onlinereport/lexemes.html
Regards, Jean
I fully agree. Heredocs should work like described here: http://en.wikipedia.org/wiki/Here_document I am a Haskell newbie, and thus don't know if a real heredoc facility already exists. If not then it seems that string-qq does nicely jump in. In this case: Thanks for providing this package. -- Manfred
participants (9)
-
Ben Millwood -
Dave Bayer -
Ivan Lazar Miljenovic -
Jean-Marie Gaillourdet -
Krzysztof Skrzętnicki -
Manfred Lotz -
Steffen Schuldenzucker -
Yitzchak Gale -
唐鳳