Re: syntax...(strings/interpolation/here docs)

{-
Unlike my rough proposal, one should aim for a combination of (mostly) in-Haskell implementation and (some) pre-processing. As Thomas Nordin has pointed out to me in private email, Hugs (Dec 2001) already supports this (module lib/hugs/Quote.hs and flag +H).
The real trick is to have the same support in all implementations.. -}
module HereDocuments where {- :set +H -} import Quote text = `` When I mentioned pre-processing, I didn't mean doing something to generate a Haskell program, I meant simple language extension (as in: syntactic sugar). It is nice that the Hugs variant of here documents is easily implemented with pre-processing, but that should be done behind the scenes. Usually, I wouldn't make such a fuss, but here documents are really not some new and experimental feature. They're an old hat, and a very useful hat. The only question is how to integrate them into the rest of Haskell. The Lewis/Nordin suggestion implemented in Hugs looks like a good compromise, but it won't do harm to bind the sugar to an option/flag for a test period. In the end, a stable form of here documents should be part of the language (not part of what you can do to it with whatever tools in whatever contexts), directly supported by all implementations. '' main = putStrLn $ trim text -- Claus

| Usually, I wouldn't make such a fuss, but here documents are really | not some new and experimental feature. They're an old hat, and a | very useful hat. The only question is how to integrate them into the | rest of Haskell. At a time when many developers pay careful attention to internationalization ("I18n"), which requires careful separation of program text (functionality) and user text (display), a feature that instead ties them more closely together seems to be a step in the wrong direction. The same argument can be made with respect to the widely recognized advantages of separating functionality (e.g., model/controller) from user interface (e.g., view). Personally, I would prefer a Haskell without Here documents. Instead of: greeting = "..." main = putStrLn $ trim text I would be happy to write: main = displayResource "greeting" leaving the system to locate the text of the greeting from a separate (perhaps locale sensitive) source at runtime, and to display it in an appropriate manner. In other words, I'd prefer to see the effort that might be spent on standardizing and implementing Here documents instead directed to designing and building I18n libraries (probably based on a more general "resource bundle" mechanism). Ultimately, it comes down to a question of what you're trying to achieve. Do you envisage Haskell as an elegant scripting language that competes with perl and ruby for quick but useful hacks? Or do you think it might better serve as a platform for writing significant user level applications with fancy user interfaces and international appeal? Of course, the two are not mutually exclusive, and the presence or absence of Here documents or resource bundles will not force the language in either way. But it will determine the "feel" of the language, and so have an impact on the way that it is perceived and used. All the best, Mark

Mark> Ultimately, it comes down to a question of what you're trying to Mark> achieve. Do you envisage Haskell as an elegant scripting Mark> language that competes with perl and ruby for quick but useful Mark> hacks? Or do you think it might better serve as a platform for Mark> writing significant user level applications with fancy user Mark> interfaces and international appeal? Neither. The chief advantage of functional languages is supposed to be their clean semantics with straightforward formalization, which allows one to be confident in the correctness of relatively large and complex bodies of code. That advantage is forfeited when trying to interface directly to messy GUI toolkits (and _all_ GUI toolkits in existence are messy). Significant applications, yes; but only the _back-ends_ of such applications. -- Ian Zimmerman, Oakland, California, U.S.A. GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087 The world has taken on a thickness of vulgarity that raises a spiritual man's contempt to the violence of a passion. Baudelaire

| ..[here documents: .. old and very useful hat]..
At a time when many developers pay careful attention to internationalization ("I18n"), which requires careful separation of program text (functionality) and user text (display), a feature that instead ties them more closely together seems to be a step in the wrong direction.
Sorry? We seem to be talking cross purposes here. What triggered this suggestion was actually a question about how to *improve* support for internationalisation in Haskell. I think that functional composition can give us a rather more expressive framework for this than the usual separation of applications into code and a text database. Few applications directly allow such a separation, especially when GUIs are involved, and even fewer improve when pressed into this scheme. Rigid code, to be patched by equally rigid text fragments, loaded from some resource-controlled database, is no replacement for text that can be parameterised by the code and code that adapts to the text (e.g., during layout or because of other variations of program behaviour necessitated by localisation). Haskell already supports unicorns (cough), and as some of these have actually been sighted in Haskell implementations, the debate on what they actually look like, or should look like, is ongoing. Haskell definitely supports abstraction and composition, so we can factor out application aspects (not just text) that need localisation, and link them (dynamically?) with the main parts of our applications. Some systematic approach would be useful, but apart from keeping track of the issues raised in the standards committees, I don't see why Haskellers should limit themselves to "the" standard way of patching C#/Java apps with translated text fragments. But that's just personal opinion. As you say,
..the presence or absence of Here documents or resource bundles will not force the language in either way. But it will determine the "feel" of the language, and so have an impact on the way that it is perceived and used.
I can only see here documents facilitating string handling. Moreover, they are usually employed exactly to write text as it should be read, parameterised as necessary, but otherwise separated from the main code, and not interspersed with string construction operations. So they also help the separation you want. For what it's worth: my personal reason for wanting here documents is meta-programming in Haskell. For instance, I generate VRML scenes with embedded ECMAScript (not my choice..) from a Haskell embedding. Others generate HTML, e.g., in web server-side Haskell scripting or documentation generators, or XML, in general data processing, or Haskell code in program transformations, or C/Java/IL/IDL.. code in compilers and interface generators, or C code in C code transformations (although Galois implemented that in SML, I think), .. and so on, and so on. Haskell may not be very efficient at representing strings, but that is (a) an implementation issue and (b) hasn't hindered string processing to become one of the major application areas for Haskell. Here documents achieve at the level of strings a subset of what metaML achieves at the level of expressions. It doesn't cost much to have them, and it costs a lot not to have them - debugging program generators without them is a mess, and even with a self-made variable substitution it is unnecessarily error-prone. I'm a bit surprised that some Haskellers apparently have not experienced here documents as an entirely benign and productivity-enhancing feature. Just because it is usually found in shells and perls, that doesn't mean it wouldn't be good enough for a "real" language. But unless other Haskell application and library programmers in need of this cry out in favour, I'll grumble on in silence (hooray for Hugs, though;-). Regards, Claus PS. Unless I'm mistaken, "I18N/L10N" is a play with characters that befits the purpose rather badly: "Internationalisierung/Lokalisierung", ..(add your own translation here)..

Ian Zimmerman
Mark> Ultimately, it comes down to a question of what you're trying to Mark> achieve. Do you envisage Haskell as an elegant scripting Mark> language that competes with perl and ruby for quick but useful Mark> hacks? Or do you think it might better serve as a platform for Mark> writing significant user level applications with fancy user Mark> interfaces and international appeal?
Neither.
The chief advantage of functional languages is supposed to be their clean semantics with straightforward formalization, which allows one to be confident in the correctness of relatively large and complex bodies of code. That advantage is forfeited when trying to interface directly to messy GUI toolkits (and _all_ GUI toolkits in existence are messy).
I don't agree. The clean semantics of FP languages has led to language features that are very useful, especially in messy contexts. I have myself written many thousand lines of what I like to call "C in Haskell syntax", much of this as part of the Haskell binding to the GTK+ GUI toolkit. This code uses pointers, side-effects, calls to C routines as well as explicit memory allocation and deallocation all over the place. Do I think Haskell is suited for writing such code? Yes, definitely. As long as you don't need close control over your memory and runtime consumption (like in an OS kernel), I would say, Haskell is the better C.[1] Haskell's type system and excellent support for higher-order functions in combination with the facilities for data structures (pattern matching etc) make it a powerful tool for everybody who knows to use these features. For example, if you use suitable types for your functions (eg, parametrised pointers), the type checker will still pick up many more mistakes than that of an imperative language. Cheers, Manuel [1] And mind you, I have programmed much more code in imperative than in functional languages.
participants (5)
-
C.Reinke
-
Claus Reinke
-
Ian Zimmerman
-
Manuel M. T. Chakravarty
-
Mark P Jones