stm-incremental: A library for constructing incremental computations

[ concurrency, control, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

A library for constructing incremental computations.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.1.0
Change log CHANGELOG.md
Dependencies base (>=4.12 && <5), stm (>=2.1) [details]
Tested with ghc ==8.6.5 || ==8.8.4 || ==8.10.2
License MIT
Copyright 2019 Samuel Schlesinger
Author Samuel Schlesinger
Maintainer sgschlesinger@gmail.com
Category Control, Concurrency
Home page https://github.com/SamuelSchlesinger/stm-incremental
Bug tracker https://github.com/SamuelSchlesinger/stm-incremental/issues
Source repo head: git clone https://github.com/samuelschlesinger/stm-incremental
Uploaded by sgschlesinger at 2023-02-02T05:57:26Z
Distributions NixOS:0.1.1.0
Downloads 575 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-02-02 [all 1 reports]

Readme for stm-incremental-0.1.1.0

[back to package description]

stm-incremental

Hackage

This library is meant to expose an interface for incremental computation using software transactional memory in Haskell.

import Control.Concurrent.STM.Incremental

main = do
  (salutation, name, greeting) <- atomically do
    salutation <- incremental "Hello"
    name <- incremental "Samuel"
    greeting <- combine (\s n -> s <> ", " n) salutation name
    pure (salutation, name, greeting)
  -- Will print "Hello, Samuel"
  atomically (observe greeting) >>= print
  atomically (set salutation "Hiya")
  -- Will print "Hiya, Samuel"
  atomically (observe greeting) >>= print

There are three operations, imap, combine, and choose. They sort of correspond to the operations of fmap, liftA2, and (>>=), but not exactly. imap allows you to construct an incremental computation depending on one other, which only ever gets updated when this single dependency does. combine allows you to construct an incremental computation depending on two others, which gets updated whenever either does. choose allows you to switch your dependency structure depending on live values in the incremental computation. In other words, this allows you to have dynamic dependencies, whereas the former two functions only allowed you to have static dependencies.

The choose combinator is the most computationally expensive, requiring in the worst case time proportional to the size of the image of the choice function passed in.