stm-actor: A simplistic actor model based on STM

[ control, library, mit ] [ Propose Tags ]

A simplistic actor model based on STM.

[Skip to Readme]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,
Dependencies base (>=4.12 && <4.17), mtl (>=1.0), stm (>=2.1), stm-queue (>=0.1), transformers (>=0.2), unliftio-core (>=0.2) [details]
License MIT
Copyright 2020 Samuel Schlesinger
Author Samuel Schlesinger
Category Control
Source repo head: git clone
Uploaded by sgschlesinger at 2022-01-21T08:48:51Z
Distributions NixOS:
Downloads 1168 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-21 [all 1 reports]

Readme for stm-actor-

[back to package description]



An implementation of a basic actor model in Haskell. With a very simple API, this is meant to serve as a basis for writing simple, message-passing style of programs. Here is an example using the etcd library.

{-# LANGUAGE BlockArguments, LambdaCase, OverloadedStrings #-}
import Network.Etcd

main :: IO ()
main = do
  client <- createClient ["machine-1", "machine-2", "machine-3"]
  logger <- act do
    receive \changes -> do
      -- we can do arbitrary things here with the reported changes, of course
      liftIO (appendFile "logfile" (show changes))
  watcher <- act do
    link logger
    liftIO $ forever do
      waitClient client "cluster-resources" >>= \case
        Nothing -> pure ()
        Just updatedNode -> atomically (send actor updatedNode)

If you want multi-node actors or you care about throughput, this is not the package for you. The design is optimized to have low latency on message receipt, and to allow for interactions between actors in transactions, using Haskell's software transactional memory.