Hacker News new | ask | show | jobs
by glowcoil 1771 days ago
There is really no way in which Rust's Send or Swift's Sendable form a monad or a functor in any of the senses of those terms.
2 comments

That doesn't change the fact that Haskell and ML did it first on their type systems, regardless how pedantic we want to discuss type theory.
The things you are saying are just not true. Standard ML and OCaml are in fact single-threaded languages, and while Haskell has concurrency and parallelism support it does not have anything that looks particularly like a Send or Sendable trait.
Concurrent ML:

http://cml.cs.uchicago.edu/pages/sync-var.html

As for the rest I am on the go to type a proper example.

Yes, Concurrent ML exists. It also, however, does not have any feature analogous to Rust's Send trait or Swift's Sendable protocol.
Of course it doesn't have a type class Sendable, that is not the point, rather the type theory behind it, and what those languages allow for, regardless of what they have in 2021 on their standard library.
While there is no exact match between them, the ``Send`` trait which can be thought of as preventing you from sharing an object between two threads actually has two monadic implementation in haskell. The ``IORef`` and ``STRef`` monads serve exactly the same purpose. This utilizes the Rank2Types extenstion. I invite you to read the Lazy Functional State Threads paper[1] by Simon Peyton Jones published in 1994.

The purpose of the ST Monad is to prevent you form sharing the object inside it wrapped by an STRef with another thread of execution.

IORef utilizes the uniqueness of the ``IO`` monad and its properties guaranteed by the haskell runtime i.e. only one thread can use it at any given time to prevent more than one thread from having a reference to the object inside the IORef from multiple.

[1]:https://www.microsoft.com/en-us/research/wp-content/uploads/...