2 ms·
A compiler takes one language (usually higher level) and transforms it into another (usually lower level). GHC, like C, go, or rust compilers, compiles to assem
by tathougies 9y ago
A compiler takes one language (usually higher level) and transforms it into another (usually lower level). GHC, like C, go, or rust compilers, compiles to assembler, a very low-level and complicated language.
One would expect that a system to transform a simple high level language into a complicated low level language would would grow proportional to how simple and high level the source language is. Thus, a very simple, high-level language ought to have a larger compiler than a more complicated, lower-level language.
Indeed, we see this in real life. Writing a haskell compiler is a fairly big undertaking whereas a C compiler could be written in a few days. This is because C is complicated, but low-level, and Haskell is simple, but high-level.
Let's not confuse the simplicity of translation with the simplicity of semantics.
- qznc 9y agoI believe a toy Haskell compiler could be made with comparable effort to toy C compilers. Admittedly, I cannot find people making toy Haskell compilers. What makes Haskell higher-level than C? Garbage collection does not really complicate the compiler if you just use BoehmGC. You can use a simple subset of assembly instead of the full complicated set. Toy C compilers do this, e.g. by treating x86 as a stack machine.