Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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...



> 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)


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!


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.


Yeah, embedded systems isn't a domain where functional programming is going to work well. Good luck with those locks! :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: