extensible-effects-concurrent: Message passing concurrency as extensible-effect

[ bsd3, concurrency, control, effect, library, program ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/sheyll/extensible-effects-concurrent#readme

[Skip to Readme]
Versions [faq],,,,,,,,,,,,,,, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8, 0.9.0, 0.9.2,,, 0.10.0, 0.11.1, 0.12.0, 0.12.1, 0.13.0, 0.13.2, 0.14.0, 0.14.1, 0.14.2, 0.14.3, 0.15.0, 0.16.0, 0.16.1, 0.17.0, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.20.0, 0.21.0, 0.21.1, 0.22.0, 0.22.1, 0.23.0, 0.24.0, 0.24.1, 0.24.2, 0.24.3, 0.25.0, 0.25.1, 0.26.0, 0.26.1, 0.27.0, 0.28.0, 0.29.0, 0.29.1, 0.29.2
Change log ChangeLog.md
Dependencies async (>=2.2 && <3), base (>=4.12 && <5), bytestring (==0.10.*), containers (>=0.5.8 && <0.7), data-default (==0.7.*), deepseq (==1.4.*), directory, exceptions (==0.10.*), extensible-effects (==5.*), extensible-effects-concurrent, filepath (==1.4.*), hostname, lens (>=4.14 && <4.18), monad-control (==1.0.*), mtl (==2.2.*), network (>=2 && <4), parallel (==3.2.*), pretty-types (>= && <0.4), process (==1.6.*), QuickCheck, safe-exceptions (==0.1.*), stm (>=2.4.5 && <2.6), tagged (==0.8.*), text (==1.2.*), time (==1.8.*), transformers-base (==0.4.*) [details]
License BSD-3-Clause
Copyright Copyright Sven Heyll
Author Sven Heyll
Maintainer sven.heyll@gmail.com
Category Concurrency, Control, Effect
Home page https://github.com/sheyll/extensible-effects-concurrent#readme
Bug tracker https://github.com/sheyll/extensible-effects-concurrent/issues
Source repo head: git clone https://github.com/sheyll/extensible-effects-concurrent
Uploaded by SvenHeyll at Thu Jun 27 20:04:43 UTC 2019
Distributions NixOS:0.29.2
Executables extensible-effects-concurrent-example-embedded-protocols, extensible-effects-concurrent-example-4, extensible-effects-concurrent-example-3, extensible-effects-concurrent-example-2, extensible-effects-concurrent-example-1
Downloads 6730 total (1615 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-06-27 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for extensible-effects-concurrent-0.29.2

[back to package description]


Build Status


From Erlang to Haskell

This project is an attempt to implement core ideas learned from the Erlang/OTP
framework in Haskell using extensible-effects.

This library sketches my personal history of working on a large, real world Erlang application, trying to bring some of the ideas over to Haskell.

I know about cloud-haskell and transient, but I wanted something based on 'extensible-effects', and I also wanted to deepen my understanding of it.

Modeling an Application with Processes

The fundamental approach to modelling applications in Erlang is based on the concept of concurrent, communicating processes.

The mental model of the programming framework regards objects as processes with an isolated internal state.

Processes are at the center of that contraption. All actions happen in processes, and all interactions happen via messages sent between processes.

This is called Message Passing Concurrency; in this library it is provided via the Process effect.

The Process effect itself is just an abstract interface.

There are two schedulers, that interpret the Process effect:

  • A multi-threaded scheduler, based on the async
  • A pure single-threaded scheduler, based on coroutines

Using the library

For convenience, it is enough to import one of three modules:

Process Life-Cycles and Interprocess Links

All processes except the first process are spawned by existing processes.

When a process spawns a new process they are independent apart from the fact that the parent knows the process-id of the spawend child process.

Processes can monitor each other to be notified when a communication partner exits, potentially in unforseen ways.

Similarily processes may choose to mutually link each other.

That allows to model trees in which processes watch and start or restart each other.

Because processes never share memory, the internal - possibly broken - state of a process is gone, when a process exits; hence restarting a process will not be bothered by left-over, possibly inconsistent, state.

Higher Level Abstractions

Processes can receive only message of type Dynamic.

In order to leverage Haskells type-safety, a bit of support code is available.

There is a data family called Api allowing to model calls and casts, as well as event management and process supervision.

These facilities are very important to build non-defensive, let-it-crash applications, resilient to runtime errors.

Additional services

Currently a custom logging effect is also part of the code base.

Usage and Implementation

Example Code

module Main where

import           Control.Eff
import           Control.Eff.Concurrent

main :: IO ()
main = defaultMain example

example :: Eff Effects ()
example = do
  person <- spawn "alice" alice
  replyToMe <- self
  sendMessage person replyToMe
  personName <- receiveMessage
  logInfo' ("I just met " ++ personName)

alice :: Eff Effects ()
alice = do
  logInfo "I am waiting for someone to ask me..."
  sender <- receiveMessage
  sendMessage sender ("Alice" :: String)
  logInfo' (show sender ++ " message received.")

This is taken from example-4.

Running this example causes this output:

DEBUG     scheduler loop entered                                                   ForkIOScheduler.hs line 157
DEBUG            !1 enter process                                                            ForkIOScheduler.hs line 549
NOTICE           !1 ++++++++ main process started ++++++++                                   ForkIOScheduler.hs line 461
DEBUG            !2 enter process                                                            ForkIOScheduler.hs line 549
INFO             !2 I am waiting for someone to ask me...                                               Main.hs line 26
INFO             !2 !1 just needed to know it.                                                          Main.hs line 29
DEBUG            !2 exit normally                                                            ForkIOScheduler.hs line 568
INFO             !1 I just met Alice                                                                    Main.hs line 34
NOTICE           !1 ++++++++ main process returned ++++++++                                  ForkIOScheduler.hs line 463
DEBUG            !1 exit normally                                                            ForkIOScheduler.hs line 568
DEBUG     scheduler loop returned                                                  ForkIOScheduler.hs line 159
DEBUG     scheduler cleanup begin                                                  ForkIOScheduler.hs line 154
NOTICE    cancelling processes: []                                                 ForkIOScheduler.hs line 168
NOTICE    all processes cancelled                                                  ForkIOScheduler.hs line 179

Required GHC Extensions

In order to use the library you might need to activate some extension in order to fight some ambiguous types, stemming from the flexibility to choose different Scheduler implementations.

  • AllowAmbiguousTypes
  • TypeApplications

Planned Features

  • Stackage extensible-effects-concurrent LTS

  • Scheduler ekg Monitoring