←back to thread

389 points kurinikku | 1 comments | | HN request time: 0.201s | source
Show context
blackeyeblitzar ◴[] No.42165532[source]
A computer fundamentally isn’t functions though. That’s not how a processor works. If functions are a useful abstraction, why haven’t functional languages taken off?
replies(3): >>42165967 #>>42167317 #>>42168684 #
1. antonvs ◴[] No.42167317[source]
> A computer fundamentally isn’t functions though. That’s not how a processor works. If functions are a useful abstraction, why haven’t functional languages taken off?

If computers and their processors are a useful abstraction, why don't we write everything directly in machine language - or microcode for that matter?

This is more about computing than about computers. As Dijkstra put it, "Computer science is no more about computers than astronomy is about telescopes."

Computing involves languages, including many languages that are not machine languages. Every language that's higher level than machine code requires translation to actually execute on the particular machines that we've developed as a result of our history and legacy decisions.

The lambda calculus is a prototypical language that provides very simple yet general meanings for the very concept of variables - or name-based abstraction in general - and the closely related concept of functions. It's a powerful set of concepts that is the basis for many very powerful languages.

It also provides a mathematically tractable way to represent languages that don't follow those principles closely. Compilers perform optimizations like static single assignment (SSA), which are fundamentally equivalent to a subset of the functional concept of continuation passing style (CPS). In other words, mainstream languages need to be transformed through functional style in order to make them tractable enough to compile.

The mapping from a lambda calculus style program to a CPU-style register machine is quite straightforward. The connection is covered in depth in Chapter 5 of SICP, "Computing with Register Machines." Later work on this found even better ways to handle this, like Appel's "Compiling with Continuations" - which led to the SSA/CPS equivalence mentioned above.

There's a lot to learn here. It's hard to recognize that if you know nothing about it, though.