references: Generalization of lenses, folds and traversals to handle monads and addition.

[ bsd3, control, library ] [ Propose Tags ]

References can read, write or update parts of the data. They are first-class values, can be passed in functions, transformed, combined. References generalize lenses, folds and traversals for haskell (see:

There are two things that references can do but the previously mentioned access methods don't.

Basic idea taken from the currently not maintained package

An example use of the references (a logger application that spawns new threads to update a global log):

logger =
  (forever $ do
     log <- logChan ^! chan&logRecord    -- Extract the log record from the received log message
     thrId <- forkIO (do time <- getTime
                         ioref&lastLogTime != time $ logDB     -- Update the last logging time mutable log database
                         let logMsg = senderThread .- show     -- Transform the thread id to a string and
                                        $ loggingTime .= time  -- update the time
                                        $ log                  -- inside the log message
                         ioref&debugInfos !~ addLogEntry log $ logDB  -- update the table of log entries
                         mvar !- (+1) $ count )
     mvar !- (thrId:) $ updaters                               -- Record the spawned thread
    ) `catch` stopUpdaters updaters
  where stopUpdaters updaters ThreadKilled =
          mvar&traverse *!| killThread $ updaters              -- Kill all spawned threads before stopping

There are a bunch of predefined references for datatypes included in standard libraries.

New references can be created in several ways:

Versions [faq],,,,,,,,,,,,,
Dependencies base (>=4.6 && <5), containers (==0.5.*), either (==4.3.*), lens (==4.2.*), lifted-base (==0.2.*), monad-control (==0.3.*), mtl (==2.2.*), template-haskell (>=2.8 && <3), transformers (==0.4.*), transformers-base (==0.4.*) [details]
License BSD-3-Clause
Author Boldizsar Nemeth
Revised Revision 1 made by lazac at 2014-08-14T12:41:51Z
Category Control
Home page
Uploaded by lazac at 2014-08-14T12:27:01Z
Distributions LTSHaskell:, NixOS:, Stackage:
Downloads 9202 total (25 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees