[Haskell-cafe] Compilers: Why do we need a core language?

Albert Y. C. Lai trebla at vex.net
Tue Nov 20 18:47:38 CET 2012

On 12-11-20 06:54 AM, citb at lavabit.com wrote:

> I know nothing about compilers and interpreters. I checked several
> books, but none of them explained why we have to translate a
> high-level language into a small (core) language. Is it impossible
> (very hard) to directly translate high-level language into machine
> code?

Let the overall distance be fixed. More steps over that same distance 
means each step is smaller, easier to design, easier to understand, 
easier to correct if there are mistakes.

Forget code generation. Just parse and validate and then discard. 
Already there are like 4 steps. Translate character sequence into token 
sequence. Translate token sequence into grammar tree, while checking 
grammar. Translate grammar tree into declaration groups, identifier 
lookup tables, etc., while checking whether every used identifier is 
declared or imported. Translate those groups and tables into 
type-annotated groups and tables, while checking types.

Whew! After 4 steps of translating this to that, we still haven't 
reached the core language! Why?

Because... have you ever tried to write a type-checker for character 

I'm sure some mad genius can do it, but I don't want to be that mad genius.

More information about the Haskell-Cafe mailing list