News for hackers. Stuff that matters.
Re:Why GitHub used Haskell for Semantic by AnimalMuppet on Wednesday June 05, 2019 @09:53PM (#20110871)
> But in some domains (or pieces of domains), state and mutation aren't just unfortunate implementation details, but a core element of the problem space. For these cases, the FP answer is usually "recompute and replace" (generally with immutable data structures that make this efficient).

It can get worse than that. My problem space has mutable state that is shared between multiple threads. FP's initial answer is "shared mutable state is evil". And they're right! But if that's the nature of your problem, then you're kind of stuck with it.

But the problem with the "recompute and replace an immutable data structure" is that I now have to notify all the relevant threads that they need to replace their reference to the data structure (avoiding race conditions in the process), and that seems at least as nasty as the problems I have doing it the imperative way.

Re:Why GitHub used Haskell for Semantic by brianberns on Wednesday June 05, 2019 @11:59PM (#20111458)
You might be interested in software transactional memory: https://en.m.wikipedia.org/wiki/Software_transactional_memor.... I believe it addresses some of the issues you mentioned in a functional programming way.
Re:Why GitHub used Haskell for Semantic by AnimalMuppet on Thursday June 06, 2019 @12:15AM (#20111531)
Interesting!

But in my world (embedded systems), those I/O writes aren't just writes to a file or a network socket. They're writes to device hardware, which has to be in the written-to state the next time that another thread interacts with it. That is, the I/O operation has to be part of the transaction, not queued up to run after the transaction commits.

Still, this approach goes farther than I thought possible to solve the problem...

Re:Why GitHub used Haskell for Semantic by lmm on Thursday June 06, 2019 @06:20AM (#20113116)
> That is, the I/O operation has to be part of the transaction, not queued up to run after the transaction commits.

That's the kind of thing Haskell excels at - explicitly sequencing things that need to happen before other things, so that you can have code that does stuff in the right order without getting into the trap of "can't ever refactor this in case I change the order something runs in".

(I can't believe that threads are actually part of the problem statement unless you're doing something strictly tied to C. Concurrency or even parallelism might be a requirement, but there are other ways to achieve it than OS-level shared-memory threads)

Re:Why GitHub used Haskell for Semantic by mbrock on Thursday June 06, 2019 @01:08AM (#20111757)
The Haskell philosophy is easily misunderstood. It's not really that shared mutable state is evil but that it's difficult and so should be treated seriously and explicitly. The language still supports it—quite well. GHC's green thread scheduler is top-shelf. The main author of the GHC runtime wrote an excellent O'Reilly book called "Parallel and Concurrent Programming in Haskell" (which you can read for free online).

https://simonmar.github.io/pages/pcph.html

Of course that's not to say that Haskell is optimal for your work in embedded systems!

Re:Why GitHub used Haskell for Semantic by jinfiesto on Thursday June 06, 2019 @02:40AM (#20112143)
Was going to say exactly this. Major common misunderstanding about even Haskell. Mutable state has to eventually be a part of basically every program that does something useful. The Haskell philosophy is more about having an explicit and predictable boundary between the pure and effectful parts of your code/system.

Though you'd be surprised at how much you can do while forgoing mutable state entirely.

Re:Why GitHub used Haskell for Semantic by brianberns on Thursday June 06, 2019 @12:59AM (#20111717)
Yeah, embedded systems isn't a domain where functional programming is going to work well. Good luck with those locks! :)
Re:Why GitHub used Haskell for Semantic by senderista on Friday June 07, 2019 @02:52PM (#20127547)
That’s a classic example of a problem that can be trivially solved with another level of indirection (reference to a reference).
Re:Why GitHub used Haskell for Semantic by Scarbutt on Thursday June 06, 2019 @12:26AM (#20111589)
Clojure's atom primitive solves exactly this problem.