Hacker News new | ask | show | jobs
by curtis 5488 days ago
Putting XML literals in the language just feels wrong. On the other hand, they've turned out to be damn useful when you're writing the back end for a web application.
1 comments

It was a mistake. A better effort would have been to implement a first-class Macro system a-la Lisp. You can see here that Nemerle supports macros and makes dealing with XML like relatively painless as if it were built in: http://nemerle.org/About/#ID0E6G

Macros for the win.

I'm curious how much you've actually used Haskell's templating system.

It is my understanding that a good macro system in a statically typed langauge is still an open research problem. I remember hearing that the Racket research group was still working on it for their typed Racket system, and that it was, at least as of a year ago, not possible to directly port macros from the standard language over to the typed language.

I also remember hearing that template Haskell is a relatively primitive macro system that very few Haskell developers currently actually use, but I'm not an expert in this area.

Scala is already cutting edge in a lot of ways. Expecting them to innovate in such a difficult and untrodden area on top of what they've already done is asking a little much, especially considering that it is meant to be a practical and not a research language.

Re: Template-Haskell - sadly not enough. I have used it to generate N-tuple-generalizations of functions in toys. I simply don't get enough time to hack around in Haskell. As far as being primitive, I guess you would have to compare that to the drudgery of emitting all the automatically generated code produced by macro expansions by hand. Yes, in Haskell TH is relatively infrequently used.

In no way am I trivializing the complexity of what would be involved in bringing a useful macro system to Scala, but compiler plugins for Scala are filling this role today, a good macro system could make meta programming more accessible. Already there are plugins for SBT to invoke FreeMarker on Scala-program templates to generate code, clearly a poor-man's solution, but it simply is more evidence that a macro-system would and would be put to good use were one available.

Taking Racket as an example, a good macro system would enable many kinds of experimentation in the Scala language without having to extend the core directly. In Typed Racket Hindley-Milner type-inference was added on-top of a dynamically typed-core, and Typed Racket targets Haskell-level (or better) typing infrastructure. All this enabled essentially due to support of Macros.

RE: Cutting edge - And Haskell isn't? While there are a number of language features where Scala may in fact outshine Haskell, I would hardly place Haskell in the old and well-trodden place on the programming language landscape. It is still evolving rapidly, and without the need to conform to any particular run-time-system (e.g. the JVM) the researchers working on Haskell are able to practically make the language warp space-time.

This comment on Typed Racket isn't correct. Lots of macros work just fine in Typed Racket, and XML literals would certainly be among them [1]. The macros that don't work yet are the most complex ones, like the one implementing an entire class system with Java and Beta style inheritance (both!).

[1] In Racket, we typically use s-expressions rather than XML literals.

Typed Racket is a marvelous wonder. Sadly, it is simply not appreciated enough for what it is: an utter triumph of Lisp over all challengers. ;-)
Disagree. Scala's syntax is already complex enough and flexible enough to all but eliminate the need for macros. XML literals were a marketing gimmick. More conventional XML support in a library would have been adequate.
Interesting. This is a common perception but not an easily justified one. A macro-system a-la Lisp (or Nemerle) could easily replace compiler plugins, and there is an active compiler plugin community so extensions to the compiler are desirable. As someone who writes in Scala every day for a living and have used the built-in XML support here and there I do not consider Scala syntax to be complex, but the XML support is ~eh~.

Despite limitations and warts it's a pretty nice language to code in on a daily basis if you're going to code on the JVM. Macros would definitely enhance Scala's productivity. If you don't like them don't use them. Certainly doesn't mean that others could not put such a tool to good use.

That's the problem with macros. It's hard enough to read Scala code as it is if the author wants to be clever. Throw in macros and it's game over. In languages with relatively inflexible or primitive syntaxes macros are a blessing but I think they're unnecessary in Scala.