On Tue, Nov 20, 2012 at 6:54 AM, <c...@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?
>

You might note that gcc does the same thing internally; its core seems to
be inspired by S-expressions.  (It's also somewhat lower level than GHC's
core, but then C is itself lower level.)

As for why:

* It's a way to remove redundancy and simplify implementation.
* Sometimes it's easier to rephrase a language feature in terms of another
similar feature, instead of duplicating code or making that code
sufficiently reusable to apply easily in multiple not-quite-identical
places.
* Sometimes it's because the language definition specifies a translation
that describes the behavior of a language feature (see, for example, do
blocks and automatically derived typeclasses in Haskell) and the simplest
way to ensure compliance with the standard is to do the same translation in
the compiler.
* It can also be easier to apply high level optimization techniques; if you
go straight from the highest level code to the lowest level, you are likely
to miss optimization opportunities that are only revealed (or only sanely
implementable) at intermediate levels.

-- 
brandon s allbery kf8nh                               sine nomine associates
allber...@gmail.com                                  ballb...@sinenomine.net
unix/linux, openafs, kerberos, infrastructure          http://sinenomine.net
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to