11

As mush as FP has done, in the end, all our programs are structured. That is, it doesn't matter how pure or functional we make a them - they are always translated to assembly, so what actually runs behind the hoods are instructions, states and loops. We are kind of emulating FP.

As a hardware noob, my question is: why aren't we using computer architectures that actually computed things in a functional style? For example, a computer could consist of primitive "functional chips" such as "concat", "map" and "reduce", and a program would merely tell the computer how to flow the data between those chips in order to compute the desired result, such as in concatenative languages.

nonsense sketch

This doesn't really make sense but might illustrate what I'm thinking.

  • 5
    Don't have the link off hand, but a Haskell chip was made, expert systems had specialized lisp hardware as well. I think you'd may be closer to the map/reduce paradigm in hardware than anything else though. The only perf benefit to FP is scalability to parallelism. In all other ways fp is less performant because it is less fine grained in it's instructions due to being a higher level of abstraction. At the metal level performance is king, and besides even at the abstraction level of math, in execution everything is imperative. Compute 2*3+5 without taking two ordered steps. It's all imperative – Jimmy Hoffa May 13 '13 at 1:26
  • 3
    @JimmyHoffa's off hand haskell chip link: Reduceron. – Dan D. May 13 '13 at 1:43
  • 1
    Also you might be interested in Verity which is a compiler for a call-by-name Lambda calculus with higher-order and affine recursion which also has imperative local effects to static hardware via VHDL. – Dan D. May 13 '13 at 1:55
  • 5
    @Dokkat: if we could make a specialized chip for Filter, for example, it would need just a single clock for a Filter operation. Not really, because Filter isn't "an operation"; it's a higher-order function that applies an arbitrary external operation to a list. You can't reduce that to a single clock cycle. – Mason Wheeler May 13 '13 at 2:06
  • 2
    @Dokkat It is a higher order function, as it takes as input a function. The ridiculous specificity is what makes your example something that can be done "in a single operation". The specific predicate function is constant, and thus it is not really a true filter. Making a filter that takes an arbitrary predicate function can't be reduced to a single clock cycle because you have no control over how many clock cycles the input function takes. – Chewy Gumball May 13 '13 at 2:31
10

They do make computers like that. It's called an FPGA. Of course, FPGAs support both sequential and combinational logic, but there's nothing preventing you from just using the combinational portion as you're suggesting.

In practice, however, sequential logic (the kind with state) is extremely useful even at the chip level. For one thing, it significantly reduces the number of logic gates required to solve a problem. For another, it solves a lot of design problems related to signals having different propagation delays.

If you're interested in that sort of thing, FPGAs are well worth checking out. There's an inexpensive arduino-like board called papilio that's great for beginners. People use it for everything from robot control to bitcoin mining.

  • Thanks for the answer, I'm reading through Wikipedia's page on it - but isn't FPGA a generic programmable hardware rather than a hardware specialized for Functional Programming, like on my sketch? – MaiaVictor May 13 '13 at 2:39
  • 1
    Google "fpga sorting algorithm" if you want to see how it's done. What you drew is a programmable combinational logic circuit, which is precisely what an FPGA is designed for. – Karl Bielefeldt May 13 '13 at 2:46
  • Splendid, I'll do my research! – MaiaVictor May 13 '13 at 2:48
  • if you have no sequencing at all then you are really looking at analogue electronics – jk. May 13 '13 at 8:48
  • 2
    @jk That's not really true; take for example the arithemtic-logical unit in a simple CPU which is digital and (pure) combinational. – m3th0dman May 13 '13 at 16:01
7

Essentiall, yes, analog computers worked that way: you were changing parameters and an electric current was modified accordingly. That is what made them "faster", for a time, in the 1950s - you did not care about the slow creation and modification of separate "states" as in the olden digital behemoths.

And arguably, quantum computers might work that way, too: if the state of some quantum phenomena depends on the state of others, then changing some "initial" state will change the following states simultaneously - no "states" inbetween.

  • 3
    +1 for mentioning quantum computers, I think the ability to do things like the OP is suggesting are going to be the main benefit to these when they actually materialize – Jimmy Hoffa May 13 '13 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.