Perspective question: Functional programming

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Perspective question: Functional programming

ypei
This is a great course and thanks for making it! After working through the whole course building a computer from the chips to the Jack OS, I wonder what changes are needed if one wants to build a computer for functional programming? I got the impression that (correct me if I am wrong)

- Currently code written in functional programming languages is compiled to imperative code, before getting translated to the machine language.
- The common CPUs we have in our computers are natural for imperative languages but not functional languages

If so, in the spirit of this course, how does one design a computer for functional programming? Does one need something different from the Von Neumann Architecture?
Reply | Threaded
Open this post in threaded view
|

Re: Perspective question: Functional programming

ivant
I meant to answer this a long time ago but got sidetracked and forgot about it. Sorry :)

Basically any real computer has finite resources, like registers and memory. So all but the smallest and most trivial programs will require changing their values and reusing these resources.

The functional programming is an abstraction, which presents a computer with unlimited and unchangeable memory. To execute on real hardware it has to simulate this, through automatic garbage collection.

Also, input and output are inherently non-functional. Languages like Haskell have developed the IO monad to present a functional facade.

That said, I'm sure there are specific hardware features that can make implementing functional programs easier. You can take a look at the Lisp Machines: general purpose computers designed specifically to run Lisp programs and operating systems.