[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua vs. Haskell (was Re: Bridging Lua to native C/C++ code automatically)
- From: Don Hopkins <dhopkins@...>
- Date: Tue, 29 Aug 2006 10:39:52 -0700
Haskel (like Lisp) is well designed (on a strong mathematical
foundation) to be compiled into efficient machine code, as opposed to a
well designed interpreted language like Lua, or badly designed
But Haskel is about as far away from a "consumer programming language"
as you can get -- it's quite weird by most people's standards, and has
been known to cause people's heads explode.
In the ideal world, more people would have less explosive heads, but
unfortunately Haskel is just too powerful and esoteric for most people
to handle. (Unfortunately, so many people use shitty languages like PHP,
so their programs explode instead of their heads.)
In the hands of a great programmer (like James Clark), it's astounding
what can be done in a few lines of Haskel, and it's interesting to
compare the amount of Java code it takes the same programmer to
implement the same algorithm.
James Clark (of xml and thaiopensource fame, not to be confused with the
suit who founded netscape) is one of the most amazing
designer/programmers of our time, and a proficient polyglot, who's
designed and implemented extremely sophisticated stuff in many different
languages. He uses Haskel as a design language to hash out XML
standards, then re-implements them in ordinary "consumer oriented"
languages like Java. It's quite interesting to compare the Haskel and
Java implementations of Relax NG!
Here's an article I wrote about some amazing Haskel code, a Relax NG
I like Lua because it's true to Clark's notion of "maximizing
An Algorithm for Relax NG Validation:
Maximizing Composability and Relax NG Trivia
Here's some interesting stuff about the design and development of Relax NG:
James Clark wrote about maximizing composability:
"First, a little digression. In general, I have made it a design
principle in TREX to maximize "composability". It's a little bit hard to
describe. The idea is that a language provides a number of different
kinds of atomic thing, and a number different ways to compose new things
out of other things. Maximizing composability means minimizing
restrictions on which ways to compose things can be applied to which
kinds of thing. Maximizing composability tends to improve the ratio
between functionality on the one hand and simplicity/ease of use/ease of
learning on the other."
Clark describes the derivative algorithm's lazy approach to automaton
"I don't agree that <interleave> makes automation-based implementations
impossible; it just means you have to construct automatons lazily. (In
fact, you can view the "derivative"-based approach in JTREX as lazily
constructing a kind of automaton where states are represented by a
canonical representative of the patterns that match the remaining input.)"
The Relax NG derivative algorithm is implemented in a few hundred
elegent declarative functional lines of Haskel, and also in tens of
thousands of lines and hundreds of classes of highly abstract complex
Clark's Java implementation of Relax NG is called "jing", which is a
Thai word meaning truthful, real, serious, no-nonsense, and ending with
Comparing the Java and Haskell implementations of Relax NG illustrates
what a wicked cool and powerful language Haskell really is. The Java
code must explicitly model and simulate many Haskel features like first
order functions, memoization, pattern matching, partial evaluation, lazy
evaluation, declarative programming, and functional programming. That
requires many abstract interfaces, concrete classes and brittle lines of
While the Java code is quite brittle and verbose, the Haskell code is
extremely flexible and concise. Haskell is an excellent design language,
a vehicle for exploring complex problem spaces, designing and testing
ingenious solutions, performing practical experiments, weighing
trade-offs, and writing succinct, elegant, mathematically rigorous
specifications that actually work. Haskell code is useful as a blueprint
for implementations in less luxurious languages like Java.
[More in the article...]
Relax NG: Design-by-Inspired-Individuals vs. Design-by-Committee
In The State of XML, Edd Dumbill explains the secret behind the success
of Relax NG:
Incidentally the RELAX NG success can equally well be framed as a case
of design-by-inspired-individuals vs. design-by-committee as much as it
can be seen as a OASIS vs. W3C thing.
Relax NG Compact Syntax: no to operator precedence, yes to annotations!
James Clark is a fucking genius! He’s the guy who wrote the Expat XML
parser, works on Relax NG, and does tons of other important stuff. Relax
NG is an ingeniously designed, elegant XML schema language based on
regular expressions, which also has a compact, convenient non-xml syntax.
I totally respect the way he throws down the gauntlet on operator
precedence (take that you Perl and C++ weenies!):
"There is no notion of operator precedence. It is an error for patterns
to combine the |, &, , and - operators without using parentheses to make
the grouping explicit. For example, foo | bar, baz is not allowed;
instead, either (foo | bar), baz or foo | (bar, baz) must be used. A
similar restriction applies to name classes and the use of the | and -
operators. These restrictions are not expressed in the above EBNF but
they are made explicit in the BNF in Section 1."
You can translate back and forth between Relax NG's XML and compact
syntaxes with full fidelity, without losing any important information.
Relax NG supports annotating the grammar with standard and custom
namespaces, so you can add standard extensions and extra user defined
meta-data to the grammar. That's useful for many applications like user
interface generators, programming tools, editors, compilers, data
binding, serialization, documentation, etc.
[More in the article...]