[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- 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
interpreted language like JavaScript.
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
schema validator.
I like Lua because it's true to Clark's notion of "maximizing
composability".
-Don
An Algorithm for Relax NG Validation:
http://www.thaiopensource.com/relaxng/derivative.html
Maximizing Composability and Relax NG Trivia
http://www.donhopkins.com/drupal/node/117
Here's some interesting stuff about the design and development of Relax NG:
http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=relax-ng
James Clark wrote about maximizing composability:
http://lists.oasis-open.org/archives/relax-ng/200102/msg00019.html
"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
construction:
http://lists.oasis-open.org/archives/relax-ng/200103/msg00011.html
"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
Java code.
http://www.thaiopensource.com/relaxng/implement.html
http://thaiopensource.com/relaxng/derivative.html
http://www.thaiopensource.com/relaxng/jing.html
Clark's Java implementation of Relax NG is called "jing", which is a
Thai word meaning truthful, real, serious, no-nonsense, and ending with
"ng".
http://www.thaiopensource.com/relaxng/jing.html
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
code.
http://www.haskell.org/
http://en.wikipedia.org/wiki/First_order_functions
http://en.wikipedia.org/wiki/Memoization
http://en.wikipedia.org/wiki/Pattern_matching
http://en.wikipedia.org/wiki/Partial_evaluation
http://en.wikipedia.org/wiki/Lazy_evaluation
http://en.wikipedia.org/wiki/Declarative_programming
http://en.wikipedia.org/wiki/Functional_programming
http://en.wikipedia.org/wiki/Abstraction_%28computer_science%29
http://en.wikipedia.org/wiki/Concrete_class
http://en.wikipedia.org/wiki/Software_brittleness
http://en.wikipedia.org/wiki/Lines_of_code
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...]
http://www.donhopkins.com/drupal/node/117
Also:
Relax NG: Design-by-Inspired-Individuals vs. Design-by-Committee
http://www.donhopkins.com/drupal/node/116
In The State of XML, Edd Dumbill explains the secret behind the success
of Relax NG:
http://www.xml.com/pub/a/2004/04/21/state.html
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.
Also:
Relax NG Compact Syntax: no to operator precedence, yes to annotations!
http://www.donhopkins.com/drupal/node/115
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.
http://www.jclark.com/
http://www.oasis-open.org/committees/relax-ng
http://www.jclark.com/bio.htm
http://www.oasis-open.org/committees/relax-ng/compact-20021121.html
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...]
http://www.donhopkins.com/drupal/node/115