All Projects → crabmusket → haskell-simple-concurrency

crabmusket / haskell-simple-concurrency

Licence: other
Small examples of concurrency in Haskell.

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to haskell-simple-concurrency

Tosdatabridge
A collection of resources for pulling real-time streaming data off of TDAmeritrade's ThinkOrSwim(TOS) platform; providing C, C++, Java and Python interfaces.
Stars: ✭ 229 (+205.33%)
Mutual labels:  concurrency
actors
Actor Model library for Dart.
Stars: ✭ 40 (-46.67%)
Mutual labels:  concurrency
gbp
Golang Best Practices (GBP™)
Stars: ✭ 25 (-66.67%)
Mutual labels:  concurrency
Polyphony
Fine-grained concurrency for Ruby
Stars: ✭ 234 (+212%)
Mutual labels:  concurrency
threads
Fork threads and wait for their result
Stars: ✭ 28 (-62.67%)
Mutual labels:  concurrency
pipeline
Pipelines using goroutines
Stars: ✭ 46 (-38.67%)
Mutual labels:  concurrency
Xenium
A C++ library providing various concurrent data structures and reclamation schemes.
Stars: ✭ 225 (+200%)
Mutual labels:  concurrency
java-red
Effective Concurrency Modules for Java
Stars: ✭ 25 (-66.67%)
Mutual labels:  concurrency
event pool
a header-only event-driven library based on c++11.
Stars: ✭ 27 (-64%)
Mutual labels:  concurrency
go-left-right
A faster RWLock primitive in Go, 2-3 times faster than RWMutex. A Go implementation of concurrency control algorithm in paper <Left-Right - A Concurrency Control Technique with Wait-Free Population Oblivious Reads>
Stars: ✭ 42 (-44%)
Mutual labels:  concurrency
Jctools
jctools.github.io/jctools
Stars: ✭ 2,833 (+3677.33%)
Mutual labels:  concurrency
BEW-2.5-Strongly-Typed-Languages
💪 Learn and implement the design patterns and best practices that make Go a top choice at high-velocity startups like Lyft, Heroku, Docker, Medium, and more!
Stars: ✭ 14 (-81.33%)
Mutual labels:  concurrency
reactor-workshop
Spring Reactor hands-on training (3 days)
Stars: ✭ 114 (+52%)
Mutual labels:  concurrency
Pyee
A port of Node.js's EventEmitter to python
Stars: ✭ 236 (+214.67%)
Mutual labels:  concurrency
Actors.jl
Concurrent computing in Julia based on the Actor Model
Stars: ✭ 95 (+26.67%)
Mutual labels:  concurrency
Joshuto
ranger-like terminal file manager written in Rust
Stars: ✭ 224 (+198.67%)
Mutual labels:  concurrency
simpledbm
SimpleDBM is an Open Source Multi-Threaded Embeddable Transactional Database Engine in Java.
Stars: ✭ 51 (-32%)
Mutual labels:  concurrency
p-ratelimit
Promise-based utility to make sure you don’t call rate-limited APIs too quickly.
Stars: ✭ 49 (-34.67%)
Mutual labels:  concurrency
concurrent-ll
concurrent linked list implementation
Stars: ✭ 66 (-12%)
Mutual labels:  concurrency
workerpool
A workerpool that can get expanded & shrink dynamically.
Stars: ✭ 55 (-26.67%)
Mutual labels:  concurrency

Haskell concurrency by example

This tutorial will introduce you to simple mechanisms for concurrency in Haskell. It was inspired by the concurrency-related chapters of Go by Example, which I found to be a great reference to Go's concurrency primitives. You can follow along with the tutorial, clone this repository and run the code locally, or open it up in FP Complete's online Haskell IDE to edit and run the code yourself.

I wrote this to:

  1. Learn more about Go's concurrency primitives by translating them. Go is frequently praised for its built-in channels and goroutines, so I was naturally interested. But at the same time, I'd like to see how we can achieve similar results in Haskell.
  2. Learn more about Haskell's concurrency capabilities, and hopefully teach you about them, too. I haven't had much cause to use them, so I'm keen to get my hands dirty and solidify my knowledge.
  3. Hopefully reach out to interested non-Haskellers who may not know about some of these features. Ah yes, my secret motives are revealed.

Running the code

If you've cloned this repository to run locally, once you have Stack, or plain GHC/Haskell platform installed, you can run any of the example files by entering, for example,

$ stack runhaskell Threads.hs

at the command-line. You can also open modules in GHCI to play around with them in a REPL:

$ stack ghci
> :load src/Threads.hs
> main

Note that you cannot compile the example files directly, but I have provided a Main.hs file which runs all the examples, and which can be compiled into an executable if you wish.

$ stack ghc --make -threaded Main.hs
$ ./Main

A brief word on syntax

As a Haskeller learning Go, I found myself regularly forgetting that <- and -> have different meanings in the two languages. In Haskell, <- is a generic operator called bind which runs some sort of action and stores the result in a variable (binds it). -> is used in anonymous functions, e.g. \x -> x + 1, and in type signatures, like Int -> Int. In Go, both of these operations refer specifically to channels, as far as I'm aware.

Further reading

This tutorial has covered some of the basic concurrency primitives available in Haskell/GHC, but I've stayed away from mentioning any of the other resources out there, or libraries you could use to simplify your code and amplify its power. So, I'll do that now.

For a far more in-depth look at a variety of techniques and libraries for doing concurrency and parallelism in Haskell, Parallel and Concurrent Programming in Haskell is the authority, and is available for free online! The book is written by the author of both the async package and GHC's parallel runtime itself.

If you're keen to use channels in your application, then you might want to take a look at the unagi-chan library, which provides super-performant channels, and even has directed channels built-in.

And if you want a higher level of composable concurrency, then stm is for you. It stands for software transactional memory, and it's all the rage these days. This wouldn't be a Haskell tutorial if I didn't link you to a research paper, so here's the classic paper introducing Haskell's implementation of STM. Trust me, it's a pretty easy read!

The pipes-concurrency library allows you to build up dynamic networks of concurrent activities.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].