5

So this is likely a silly question but I am just a little confused.

So I understand the Haskell compiler is itself written in Haskell. How does this work? What does it compile to? What is the OCaml compiler written in?

Also, they say using a functional language like haskell or OCaml. Can someone go through the steps of what is going on when this happens? So the new language would be compiled to haskell which would then be compiled to whatever the haskell compiler compiles to?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Jonovono
  • 3,437
  • 5
  • 42
  • 64
  • 8
    The process of writing a compiler in its own language is called [bootstrapping](http://en.wikipedia.org/wiki/Bootstrapping_(compilers)). The initial version of the compiler is not written in the target language; it is written in another language. – Robert Harvey Mar 27 '13 at 17:23
  • 3
    As for the question in the title, see: [Implementing functional languages: a tutorial](http://research.microsoft.com/en-us/um/people/simonpj/papers/pj-lester-book/) by Simon Peyton Jones and David Lester. – hammar Mar 27 '13 at 17:58
  • 3
    This is a real, constructive question. The OP simply wants to understand bootstrapping, but didn't know what it was called. Please reopen. – luqui Mar 27 '13 at 19:36
  • @luqui: The question is already answered completely and satisfactorily [here](http://en.wikipedia.org/wiki/Bootstrapping_(compilers)). – Robert Harvey Mar 27 '13 at 20:23
  • 3
    @RobertHarvey: unless it's been asked and answered on StackOverflow, I think it's a fair question. Just the fact that the information's available on the internet would rule out a lot of good questions. – amindfv Mar 27 '13 at 20:26
  • @amindfv: It's not even a real question. "How do functional language compilers work?" You could write a whole book about that. Maybe three. – Robert Harvey Mar 27 '13 at 20:27
  • 2
    Yes, much better now as duplicate than "not constructive" – luqui Mar 27 '13 at 20:41
  • 6
    The bootstrapping history of ghc goes something like this, ghc is written in Haskell and was first compiled with hbc (it's a bit more complicated than that, but good enough), hbc was written in LML, lmlc (the LML compiler) was first written in an unnamed functional language, this compiler for this unnamed language was written in C. Now we're back to 1981, and I won't go into how the C compiler was produced. – augustss Mar 28 '13 at 08:37

0 Answers0