monad-atom-0.4.1: Monadically convert object to unique integers and back.

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) 
Ord a => MonadAtom (Atom a) 

data AtomT a m r Source

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

Instances

MonadTrans (AtomT a) 
Monad m => Monad (AtomT a m) 
Functor m => Functor (AtomT a m) 
MonadIO m => MonadIO (AtomT a m) 
(Ord a, Monad m) => MonadAtom (AtomT a m) 

toAtom :: MonadAtom m => Key m -> m IntSource

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

fromAtom :: MonadAtom m => Int -> m (Key m)Source

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

maybeToAtom :: MonadAtom m => Key m -> m (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 r -> rSource

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

evalAtomT :: (Ord a, Monad m) => AtomT a m r -> m rSource

evalAtomT c runs computation c in the AtomT monad transformer with the empty initial AtomTable.

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

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

runAtomT :: (Ord a, Monad m) => AtomT a m r -> AtomTable a -> m (r, AtomTable a)Source

runAtomT c s runs computation c in the AtomT monad transformer with the initial AtomTable s.

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

The mapping stored in the atom table