reference-0.1: A class for references in Haskell

Portabilityportable
Stabilitynone

Data.Reference

Description

Reference is class which generalizes references and monads they exists in. It means that IORef, STRef and others can be accessed by common interface.

Synopsis

Documentation

class Monad m => Reference r m whereSource

Class connecting mutable variable and monad it exists in.

Methods

newRefSource

Arguments

:: a

An initial value

-> m (r a) 

Create new reference.

readRefSource

Arguments

:: r a

Reference

-> m a 

Reads a reference.

writeRefSource

Arguments

:: r a

Reference

-> a

New value

-> m () 

Write to reference.

modifyRefSource

Arguments

:: r a

Reference

-> (a -> m (a, b))

Computation

-> m b

Result of computation

Modify the reference. Default implementation is provided but it MUST be overloaded if the reference is atomic to provide an atomic write.