Domain-specific Embedded Languages and Program Generators
started 5/16/2002; 12:58:03 PM - last post 5/24/2002; 1:17:56 PM
|
|
Ehud Lamm - Domain-specific Embedded Languages and Program Generators
5/16/2002; 12:58:03 PM (reads: 3462, responses: 13)
|
|
Domain-specific Embedded Languages and Program Generators |
Samuel N. Kamin. Research on Domain-specific Embedded Languages and Program Generators, 1998.
A nice paper about building DSLs by embedding (i.e., your DSL is basically a set of functions inside a host langauge). The paper uses ML. These days I think Haskell would be the language of choice.
The DSLs in the paper are program generators: their execution results in C++ code, which can then be used inside other systems.
Since the programs generated implement parsers, this paper is also a good reminder on the difference between the various parsing techniques (LL vs. LALR etc.).
Posted to DSL by Ehud Lamm on 5/16/02; 12:59:10 PM
|
|
|
|
Chris Peterson - Re: Research on Domain-specific Embedded Languages and Program G
5/16/2002; 7:27:40 PM (reads: 2338, responses: 0)
|
|
These days I think Haskell would be the language of choice.
Why are DSLs so often associated with Haskell? I've read a few DSL papers and they always seem to use Haskell in their examples.
|
|
Ehud Lamm - Re: Domain-specific Embedded Languages and Program Generators
5/16/2002; 9:38:31 PM (reads: 2326, responses: 3)
|
|
See these slides from a presentation I linked to the other day. They list the language features that make Haskell attractive.
|
|
andrew cooke - Re: Domain-specific Embedded Languages and Program Generators
5/17/2002; 9:07:09 AM (reads: 2385, responses: 2)
|
|
Why is lazy evaluation so important? (Someone said Haskell is replacing ML so presumably lazy evaluation must be worth the trouble of monads).
Related, I guess (I have no idea really!) that most DSLs require internal state. Doesn´t that mean that any end-user code written using a DSL embedded in Haskell will have to use the "Monad syntax" (I'm assuming that the target user isn't supposed to understand monads)? Sounds a bit messy.
|
|
Ehud Lamm - Re: Domain-specific Embedded Languages and Program Generators
5/17/2002; 1:20:58 PM (reads: 2441, responses: 1)
|
|
I am still thinking about this, but let me try to give a bit more detail.
Suppose you want to add if to an eager language. You cannot write a function to implement this functionality, since if is lazy: the then part is not executed before the if function executes (eager), only when needed (lazy).
Had you used an eager language you'd have to write if as a macro (hopefully the language you use has a good macro facility. Most don't).
So a lazy language gives you flexible evaluation order.
Indeed behind the scenes your are going to use mondas. But these can be hidden from the programmer using the DSL, so this is less of an issue.
|
|
andrew cooke - Re: Domain-specific Embedded Languages and Program Generators
5/17/2002; 1:46:50 PM (reads: 2517, responses: 0)
|
|
Thanks. I get the lazy bit, but I still don't see how a DSL implementor can "hide" monads. If you use monads in Haskell they "pollute" everything (as far as I understand things). So if you're embedding inside Haskell then the end-user is going to be forced to write code that is aware of Monads (at the very least, they have to use the syntactic sugar for sequencing with monads - the semicolon stuff - and as soon as they try using monads themselves they're going to be in for a nasty shock (it's non-trivial, afaik, to combine monads)).
The only ways round this that I can think of are to either use unsafe operations or write a parser on top of Haskell. Neither seems very nice.
|
|
Ehud Lamm - Re: Domain-specific Embedded Languages and Program Generators
5/17/2002; 2:51:24 PM (reads: 2299, responses: 0)
|
|
I hvaen't really played with these things, but here's what I think.
As long as you program in the DSL itself, their mondaic nature can be hidden from you. When you try to combine it with 'regular' Haskell code, you must take into account the fact that the code is monadic.
BTW, you can find more details of this approach in Hudak's paper (esp. section 5, Modular Mondadic Interpreters).
|
|
jon fernquest - Re: Domain-specific Embedded Languages and Program Generators
5/21/2002; 4:12:06 AM (reads: 2266, responses: 0)
|
|
Definitions for each of the three components in the title
"Domain-specific Embedded Languages and Generators"
would be useful:
- Domain Specific Language
- Embedded Language
- Program Generating Language
I'd like to make some comments about an interesting
non-functional family of languages that seem to bear
two of the above three characteristics.
The Waba language and its forks
SuperWaba and Ewe (Open Source) are interesting
examples of embedded languages:
- www.ewesoft.com
- www.wabasoft.com
- www.superwaba.org
They use Java's syntax, compiler, and subsets of its class library,
virtual machine, and bytecode specifications,
to "grow a language" from scratch,
re-using the more established language's already existing ,
thoroughly tested syntax and api's.
Waba is useful yet, because it's small size and re-use of
key features in the larger language, easy to understand and
comprehend as a whole like the numerous "toy" examples
people use to illustrate a point in papers and textbooks.
Are the Waba Languages "Domain Specific" ?
They certainly aren't general purpose.
They're made for communication, entry, display,
and storage of information on small mobile devices.
They include special constructs that integrate these capabilities
like Ewe's "Live Objects" :
"objects that, in a way, 'know' how to display
themselves on the screen, how to allow users
to edit themselves, how to validate their own data
and how to encode/decode their data to savable text strings."
(Programming Ewe - Live Objects)
Waba takes the exact reverse strategy of
"program generating languages" .
It doesn't even deal with syntax because it's
embedded in Java generating and executing Java bytecode.
Maybe, "Waba Platform" would be better than "Waba Language" ?
(Kamin defines a "program generating language" to be a
"language in which programs are actually specifications for
programs in other languages." Apparently, the "host" and "target"
languages cannot be the same. (Kamin's host: SML, Kamin's target: C++)
The syntax apparently has to be different, the syntax in the host being better
suited to specifying programs of a specific domain rendered in the target
language. )
Cheers,
Jon Fernquest
|
|
Chris Rathman - Re: Domain-specific Embedded Languages and Program Generators
5/21/2002; 7:29:08 AM (reads: 2250, responses: 0)
|
|
Using those definitions reminds me of two other languages. Lua aspires to be an embedded language, useful for as a plugin for scripting purposes for other applications - the small footprint is the number one criteria for embedded languages. Another language that comes to mind is REBOL - which seems to be somewhat domain specific - aiming at internet communication.
One thing I notice about these two languages, though, is that although the motivation was narrow in focus, the languages themselves wind up being general purpose. I'd speculate there is pressure to widen up any DSL, as users attempt to use the language for disparate purposes. What may start out as a DSL, ends up being a full blown programming language.
A special purpose language like Oak that's geared towards devices talking to one another over a network connection, winds up being a be-all language like Java. The problem, of course, is that the design decisions that made sense in a limited domain become an impediment to uses for applications that fall outside of the targeted domain.
|
|
andrew cooke - Re: Domain-specific Embedded Languages and Program Generators
5/21/2002; 9:40:30 AM (reads: 2244, responses: 0)
|
|
I've finally read Hudak's paper. I was a bit disappointed to find that in many cases DSL seems to be a synonym for library (my impression of the Fran work). In these cases I think Haskell is used (apart from the laziness issue covered above) because the syntax is so "nice" - you can make your DSL look more like a language than a library.
On monads, however, the paper is pretty light. It turns out that all the nasty details (and they're pretty nasty to non-Haskell-wizards like me) are in the paper at http://www.cse.ogi.edu/~mpj/pubs/modinterp.html which dives into the details of combining monads etc. Note that the result, while elegant, is fantastically inefficient, hence the need for partial evaluation. Also, they end up dropping Haskell for Gofer because they needed extra oomph.
So I think it's fair to say that Haskell is nice for papers and simple "library DSLs", but for heavy lifting you can get into some deep monads doodah...
|
|
Noel Welsh - Re: Domain-specific Embedded Languages and Program Generators
5/22/2002; 12:15:57 AM (reads: 2217, responses: 0)
|
|
Maybe I'm a Lisp bigot but...
How does Haskell compare to Lisp for DSLs? As I see the pros and cons, for Haskell we have type checking (syntax extension is a non-issue when the syntax is as regular as Lisp's). For Lisp we have macros which allow one to write compilers for DSLs, as opposed to interpreters in Haskell. This can get around the performance problem and I think is an important advantage (and hey, you can build type checking into your macros if you want).
|
|
Ehud Lamm - Re: Domain-specific Embedded Languages and Program Generators
5/22/2002; 10:37:47 AM (reads: 2180, responses: 0)
|
|
Andrew, I think your analysis is correct. However, I feel that most of the time you can build DSLs and not need to get into 'heavy lifting'. Of course there are times you must compile all the way down to native code.
Remember that you can usually transform an interpreter into a compiler (or at least do enough partial evluation to speed things up).
|
|
Ehud Lamm - Re: Domain-specific Embedded Languages and Program Generators
5/24/2002; 3:01:48 AM (reads: 2145, responses: 1)
|
|
I'd speculate there is pressure to widen up any DSL, as users attempt to use the language for disparate purposes
This is one of the arguments for embedding DSLs inside general purpose languages. This way you can always use the underlying language facilities. I think Shivers talks about this in his Lambda: The Ulitmate Little Language paper.
|
|
Ehud Lamm - Re: Domain-specific Embedded Languages and Program Generators
5/24/2002; 1:17:56 PM (reads: 2217, responses: 0)
|
|
In the end, what I think set PHP apart in the early days, and still does today, is that it always tries to find the shortest path to solving the Web problem. It does not try to be a general-purpose scripting language -- from a recent interview with Rasmus Lerdorf, creator of PHP.
|
|
|
|