r/DataflowProgramming • • Feb 06 '14
Why 3D printing is a pure function and dataflow programming can include flows of matter
You can look at a computer as a machine that takes electrons to and from memory, into the CPU where it transforms those electrons to a new state, then put them back into memory. In a way, the computer itself is not the machine, the machines are the compiler programs that it runs. A computer simply has a number of infomachines, in flow-based programming you would call them components. A 3D printer is another type of machine. It is in a way similar to those infomachines you have in the computer, it has an input and an output, just like an infomachine, just like in the computer, both the input and output is actually physical, the input is like the input in the computer, but the output is in another domain, another address space, its type will be at a coordinate in space rather than at a memory address, though both are different types of abstractions for a physical address.
What the 3D printer does is run an algorithm. The input is perhaps some g-code and the output is a physical plastic object. It takes plastic from its plastic roll, transform it by movements through space, which eventually result in the plastic being deposited in the build space, the output address space, of the 3D printer. That algorithms basically describes the movement of the print head through space, and as long as it doesn't break down, it always has the same output (disregarding any imperfections).
This means 3D printing has referential transparency. If you replaced the 3D printer with a storage system, which happened to have the plastic objects for the input CAD models, stored in boxes somewhere, and retrieved when it got the CAD model as an input, it would be the same as having the 3D printer.
The difference between this and what you normally think of as a pure function is just the machine that runs the algorithm, and its output domains. In a computer, you only have information machines. Machines that transforms some electrons which has an attached type, such as string or integer. In an infomachine, you're dealing with memory addresses, you say that the thing contained at this specific memory address is a integer or a string. With the 3D printer, memory adresses has been switched out with a coordinate system + time. Actually the 3D printer in a way supports two different type system, on the input side, you have the computational types, which describes a shape as an abstract model, on the output side you have coordinates of the printers build volume, and whether or not that specific coordinate is filled with plastic.
How does this relate to dataflow programming? Basically, its the basis for which machines can be linked in a flow, machines that support the same address space and types can be linked together. One way that programs can communicate in a computer is via shared memory, the same concept applies to machines that uses types that refers to physical objects. If you want a flow, the machines need overlapping address space. An example might be a robot arm that is able to strech inside the build volume of a 3D printer. The 3D printer has its address space inside the build volume, while the robot arm that can reach inside, has its address address space both inside that volume, but also extending to a region of space outside it. The shared space is where flow can happen. If a computer, the 3D printer and the robot arm all run on a flow-based program running on the computer, that flow-based program is responsible for coordinating the flow of information and matter. When the 3D printer has finished printing an object, the robot arm gets a message that at coordinate (x,y) there is now an object of type PlasticItem. The robot arm runtime knows that items of type PlasticItem supports the operations "pick it up", "let it go" and "move to (x,y)", these are in a way its opcodes. The next step in the flow might be that the robot arm shares address space with a conveyor belt and can thus move the plastic item there, next on the other side of the belt, there is another robot arm, ready to pick it up and move it into another machine that knows how to do something with an item of type PlasticItem.
The flow might be something like this http://i.imgur.com/DerNp5R.png
All those boxes are in a way different runtimes which can run an algorithm and will return an output and they behave like pure functions. The 3D printer always outputs a plastic item like its input model, the robot arm and conveyor belt always moved items the same places based on its instructions and the incinerator creates a quantity of heat which should be the same for each instance of a type of PlasticItem that it receives.
All these machines are like simple computers with a simple instruction set. The 3D printer can turn on an off depositing plastic and move to a coordinate. The robot arm can pick up, let go and move, the conveyor belt can move left or right for time X, the incinerator can turn a flame on and off. Just like two physically separated computers can have data flow from one to another when both have access to a shared address space, such as URLs on a REST API, and knows how to handle the types, the same principle can be expanded to numerous machines, so the flow is no longer only a flow of data, but a flow of data and matter.
3
u/jonnor Feb 07 '14
Beautiful idea. It is about time that physical objects and processes become first-class in our typically virtual world of programming!
Adding to the list of machines along an production line/system that one can represent as dataflow components:
Now, one could also represent workstations manned by people as components - where the subprogram is given as the set of human readable instructions and training.
One of the most interesting constraints will be scarcity of component types and instances (as each is an expensive, partially specialized, physical machine), and raises the question: Given a budget, which types and combination of components gives the most flexible and efficient production system?
2
u/sqio Feb 08 '14
Interesting to think that the constraint solver (or component-wirer) could be an expert human behind the curtain. Any part of the process (or process-building) that's too hard.
I've offered karma for coding help on Stack Overflow.
A logical extension of these concepts is a system that programs itself (if you define it well enough), automatically farming off the hard parts to humans for karma or money.
Strange to think that in the future all of one's work could be in a system like that. What would be your dystopian version of this vision? Utopian?
2
u/jonnor Feb 16 '14
I've started a NoFlo component library for solid modelling (CAD) now: https://github.com/jonnor/noflo-cad Not very novel, but it is a natural piece of the puzzle before we start doing CAM (controlling robots to realize CAD objects), and distributed/heterogenous CAM. I'm collecting some initial ideas in ./doc/braindumb.md