monad-atom-simple-0.0.2: Monadically map objects to unique ints.

Safe HaskellNone

Control.Monad.Atom

Description

The Atom monad provides functions which convert objects to unique atoms (represented as Ints). Example:

 example = evalAtom $ do 
   xs <- mapM toAtom "abcabd"
   zs <- mapM fromAtom xs 
   return $ zip zs xs
>>> example
>>> [('a',0),('b',1),('c',2),('a',0),('b',1),('d',3)]

Synopsis

Documentation

data AtomTable a Source

AtomTable holds the state necessary for converting to and from Ints.

Instances

data Atom a r Source

Atom is a specialized state monad for converting to and from Ints.

Instances

Monad (Atom a) 
Functor (Atom a) 

toAtom :: Ord a => a -> Atom a IntSource

toAtom x converts x to a unique Int in the Atom monad

fromAtom :: Int -> Atom a aSource

fromAtom i converts the Int i to its corresponding object in the Atom monad.

maybeToAtom :: Ord a => a -> Atom a (Maybe Int)Source

maybeToAtom x converts x to a unique Int in the Atom monad only if x already has a corresponding Int

empty :: Ord a => AtomTable aSource

empty is the initial empty AtomTable

evalAtom :: Ord a => Atom a t -> tSource

evalAtom c runs computation c in the Atom monad with the empty initial AtomTable.

runAtom :: Ord a => Atom a t -> AtomTable a -> (t, AtomTable a)Source

runAtom c s runs computation c in the Atom monad with the initial AtomTable s.

mapping :: Ord a => AtomTable a -> Map a IntSource

The mapping stored in the atom table