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

[ bsd3, control, library ] [ Propose Tags ]

References are data accessors that can read, write or update the accessed infromation through their context. They are first-class values, can be passed in functions, transformed, combined. References generalize lenses, folds and traversals for haskell (see: https://hackage.haskell.org/package/lens).

References are more general than field selectors in traditional languages.

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 https://hackage.haskell.org/package/yall.

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] 0.1.0.0, 0.2.0.0, 0.2.1.0, 0.2.1.1, 0.2.1.2, 0.3.0.0, 0.3.0.1, 0.3.1.0, 0.3.1.1, 0.3.2.0, 0.3.2.1, 0.3.2.2, 0.3.3.0, 0.3.3.1
Dependencies array (==0.5.*), base (>=4.6 && <5), containers (==0.5.*), directory (==1.2.*), either (==4.3.*), filepath (==1.3.*), instance-control (==0.1.*), mtl (==2.2.*), template-haskell (>=2.8 && <3), text (==1.1.*), transformers (==0.4.*) [details]
License BSD-3-Clause
Author Boldizsar Nemeth
Maintainer nboldi@elte.hu
Category Control
Home page https://github.com/lazac/references
Uploaded by lazac at Sun Oct 19 19:27:28 UTC 2014
Distributions LTSHaskell:0.3.3.1, NixOS:0.3.3.1, Stackage:0.3.3.1
Downloads 5728 total (241 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2016-12-13 [all 7 reports]

Modules

  • Control
    • Control.Reference
      • Examples
        • Control.Reference.Examples.TH
      • Control.Reference.InternalInterface
      • Control.Reference.Operators
      • Control.Reference.Predefined
        • Control.Reference.Predefined.Containers
          • Control.Reference.Predefined.Containers.Tree
      • Control.Reference.Representation
      • TH
        • Control.Reference.TH.Records
        • Control.Reference.TH.Tuple
      • Control.Reference.TupleInstances

Downloads

Maintainer's Corner

For package maintainers and hackage trustees