
Robert Krook's survey of thirty years of distributed Haskell sorts seven systems by one question — what actually crosses the wire when work moves — and finds that shipping a graph of closures is the easy half.
![Two tree-shaped graphs side by side, each beginning with a downward arrow labelled root. On the left, the arrow falls into a pair node, then two cons nodes, then four leaf boxes labelled #1, #2, #3 and #4 plus one labelled [], with an extra edge running from the lower cons node across to the [] box. On the right, the same upper structure, but its four leaves read #1, a red double-outlined box labelled FM, #3, and another red double-outlined box labelled FM.](https://storage.neodrop.ai/grains/media/V3uHOC_87tGR-JFqMFaNN.png?w=640)
FM) nodes.1allPEId, rforkIO, revalIO. 1Immobile type class exposes owningPE and a thread can ask which element holds one. 1 Concurrent Haskell's MVars were extended to work across elements and became the way threads on different ones exchanged data. 1Process a b is a function from a to b that can be instantiated remotely; the # operator applies it, and the result arrives as a lazy placeholder that blocks until the process finishes. 1process, and the instantiation performed by #. 1Trans marks the types that may cross between processes, and NFData forces a value to be evaluated before it is communicated. 1new, and each of those channels can be written once; a second write raises an error. 1MChannels, higher-order channels that carry values including functions, IO actions and other channels. 1rforkIO :: IO () -> HostName -> IO () takes an IO action and starts it on the named host.putStrLn for instance, take a different route: they resolve against code already installed on the receiving machine. 1Int -> Int can have environments with entirely different serialisation needs, so whether a function can be serialised is unanswerable from its type. 1Static a, with a typing rule drawn between top-level and local bindings.static e is accepted only when every free variable of e refers to a static top-level binding, which lets a static function be represented by a code label that every node resolves locally. 1spawn :: NodeId -> Closure (ProcessM ()) -> ProcessM ProcessId. The caller picks the node and hands over a Closure; a bare ProcessM () action fails to typecheck. 1Closure is a source-level Haskell value describing how to rebuild a value on another node, and it stands apart from the GHC heap closures in the GUM section. Its representation splits the two halves apart:data Closure a where
MkClosure :: Static (ByteString -> a) -> ByteString -> Closure aStatic field names a reconstruction function that is installed on every node and has no hidden dynamic environment. The ByteString holds the environment, serialised at the construction site where its type is still known, because inside Closure a that type is gone. 1\y -> x + y + 1 to send and does not compile, because Int -> Int identifies no code and reveals no x.sendFunc :: ProcessId -> Int -> ProcessM ()
sendFunc p x = send p clo
where
clo :: Closure (Int -> Int)
clo = MkClosure (static sfun) (encode x)
sfun :: ByteString -> Int -> Int
sfun bs y = let x = decode bs in x + y + 1Par monad, in which computations create parallel tasks and pass results through single-assignment variables called IVars. A piece of work available for parallel execution is a spark, the same word multicore GHC uses. 1data Closure a = UnsafeMkClosure a (Static (ByteString -> a)) ByteStringmapClosure :: Closure (a -> b) -> Closure a -> Closure b builds both representations of the result while asking a and b for no instances at all, which is what makes polymorphic evaluation strategies and algorithmic skeletons definable on top of the task interface. 1IVars rather than mailboxes. An IVar is written once and a read blocks until the value arrives; a local IVar can be turned into a GIVar that a remote task writes with rput, and no operation reads a GIVar remotely. 1| System | Unit of execution | What may cross | Code needed at the far end |
|---|---|---|---|
| GUM | A Haskell thread on a logical processing element | Heap closures, a bounded subgraph, Fetch-Me placeholders | The same compiled program on every element 1 |
| Glasgow Distributed Haskell | A Haskell thread started on a named element | Closures and MVars | The same compiled program on every element 1 |
| Eden | A process, a function instantiated remotely | Values with a Trans instance, forced by NFData | The same compiled program on every node 1 |
| mHaskell | An IO action sent over a named channel | A serialised graph carrying GHCi bytecode | A compatible patched GHC runtime, the native libraries, the data types used 1 |
| Cloud Haskell | A process with a mailbox | Messages with a Serializable instance, and Closures of static code plus environment | The same program on every node 1 |
| HdpH | A spark, a serialisable closure | A static deserialiser and serialised environment, plus GIVar results | The same program on every node 1 |
| Unison | A definition identified by hash | Definitions, fetched by hash on demand | Nothing specific to the application 1 |
Serializable and Static; mHaskell and CloudMicroHaskell leave that check to run time, where the same mistakes surface later. The choice settles which errors a compiler can refuse for you.sfun and serialises x beside it. Any language doing closure conversion by hand runs into the same job.NFData before sending them; Krook's warning about laziness shows what happens without that step, since the size that crosses is the unevaluated graph and a small-looking value can carry a large one."One problem runs through every system: when work moves from one machine to another, what actually moves?""GUM is important here because it demonstrates that a distributed runtime can move the state of a lazy computation by operating directly on its heap graph. It also exposes a central limitation that will recur throughout this post, that moving a graph of closures is not the same as moving the executable code to which those closures refer.""Cloud Haskell therefore does not transmit executable code in the manner of mHaskell. It transmits a reference to installed code together with the data needed to reconstruct its environment.""It is also invisible to the programmer precisely what the price of laziness is. A small value might be represented by a large, unevaluated graph, which will be more costly to serialise, transmit, and deserialise."— Robert Krook, Distributed Haskell — A Survey
krook.dev
haskellweekly.news
unison-lang.org
This story was produced automatically by a channel. One sentence is all it takes for Neodrop to keep producing for you.