[Haskell-cafe] Writing a compiler in Hakell (continued 1)
lrpalmer at gmail.com
Wed May 6 07:17:13 EDT 2009
On Wed, May 6, 2009 at 4:17 AM, Rouan van Dalen <rvdalen at yahoo.co.uk> wrote:
> As for the target language, im not quite sure yet. I am doing a lot of
> work in
> .NET/C# at the moment, but I would eventually like to use my own
> programming language,
> instead of C#. I would also like to use my language for linux programming,
> so I will eventually
> support both Windows and Linux environments.
C# seems like a fine choice for target language, at least for starters. The
CLR is a great virtual machine, with a good garbage collector and a mature
JIT engine. Mono is also pretty nice and will give you support for linux.
> My aim with this project is to further explore haskell and deepen my
> understanding of it, while at
> the same time creating something useful where I can explore my own ideas
> about programmnig
> languages and concepts. I don't really intend to write "the next
> programming language" used by billions of people.
> If others find it useful, that's awsome. I definitely intend to use my
> language for my own projects and
> to make it freely availble on the net. So it is not just for learning or
> fun, it is more focused on implementing
> a decent programming language that can be used for commercial applications
> (and fun).
Great! Yes, absolutely write your compiler in your language itself after
you have bootstrapped a little bit of it. This will stress-test the
viability of your language to complex symbol manipulation tasks, and also
give you the kind of self-referential improvements you see from such a
> The compiler for my language should have a decent compile time, comparing
> to compilers written in C.
That's not too hard. The design of C is terrible for that. Recompiling
every header file each time it is included! With a decent module system and
interface format it shouldn't be that hard to compete with C.
> The approach that I have in mind is to piggy back on existing
> languages/compilers until their implementation
> is no longer adequite or I have time to write my own code generator. So
> the first stage would be something like
> translate to C# and then use the C# compiler to obtain an executable. I
> want the first steps to go as quick as possible
> so that I can refine the language and test ideas quickly, and once the
> language has stabalized, concentrarte on my
> own full fledged compiler (if it is necessary).
> I think I will try Parsec as a starting point for creating a parser.
A final bit of advice. A compiler is best as a composition of lots of very
small compilers (sans parsers; keep your data structured). Use lots of
intermediate formats, and keep the translation between each intermediate
format as small as possible. See UHC for an excellent example of this
In particular, aim for getting your language down to the smallest core
calculus that you can think of. This makes it very easy to write
interpreters, code generators and optimizers.
A compiler is a large project, but you will safe yourself a lot of pain and
complexity if you think of it as a bunch of small ones.
Good luck! I'm interested to see what your language looks like
(particularly the features you think are missing from your inspriations).
And also have fun learning Haskell; you may find your principles of
language design changing along the way as a result... :-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe