[Haskell] Scripting language: is Haskell a good choice?

Cale Gibbard cgibbard at gmail.com
Thu Jan 26 15:32:26 EST 2006

On 24/01/06, Jules Jacobs <julesjacobs at gmail.com> wrote:
> Hi,
> I would like to create a scripting language, similar to Ruby, Perl and
> Python. Pugs, written in Haskell, is a Perl6 implementation. Is Haskell a
> good choice for me? I have no experience with Haskell (yet), but I like the
> concept of functional programming. Because Haskell will probably be too slow
> for the final implementation, I will have to rewrite it in C or maybe D.

You might be surprised here. What are you scripting? It should be
possible to get more than acceptable performance for most tasks. Hey,
GHC is only second to GCC in the computer language shootout right now.

> Haskell can be very useful as a test/prototype implementation, where speed
> is not very important. But will I be able to create a clean, and easy to
> understand implementation in Haskell? The scripting language will be object
> oriented, and imperative. Is that a problem because Haskell is functional,
> or is there be an obvious and nice way to implement an imperative scripting
> language?

Well, it shouldn't matter too much. You'll probably represent your
abstract syntax directly with some data type, and implement the
interpreter as a map from that type to IO (or a monad over IO with
some extra features, like a symbol table).

> The language is very dynamic, and the source-tree needs to be in memory
> because it is modifiable at run-time.

It shouldn't be too hard to allow for that sort of thing to happen,
but I wouldn't be able to suggest an implementation without knowing
more about it.

> Would it be good to do this in Haskell, and port it to C if I like the
> implementation, or start in C? Keep the parser/lexer for the source code in
> Haskell, but port only the interpreter to C?

Porting things from Haskell to C would be a pain in general. You can
usually expect a factor of 10 to 15 blowup in the amount of code you
have to write, and you'd generally need a fairly major redesign of how
the thing works internally. Haskell supports various mechanisms like
laziness and parametric polymorphism that don't have easy translations
to C. One thing you might try is to write a bytecode compiler for the
language in Haskell, and write a bytecode interpreter in hand-tuned
C/Assembler or something.

> What would be a good place to start? I am reading Yet Another Haskell
> tutorial, and I've read the first 6 of two dozen lessons in Haskell. What to
> do next, practice/read more/start with the implementation of the scripting
> language?

It's probably *possible* to start, but be aware that you may want to
rewrite large chunks of code later. It's probably better to practise
on smaller projects and read more. Then again, if you start with a
tiny subset of the language you have in mind, writing an interpreter
for that would probably be a good way to learn, so you might do both.

Also, if you haven't checked it out yet, we have a great IRC channel,
#haskell on freenode, where you can ask questions and get help. Early
on in my progress, I learned a lot just by lurking there, and stealing
people's homework problems to do myself :) Most everyone there is
pretty friendly, and eager to help.

 - Cale

More information about the Haskell mailing list