Safe Haskell | None |
---|
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)]
- data AtomTable a
- data Atom a r
- toAtom :: Ord a => a -> Atom a Int
- fromAtom :: Int -> Atom a a
- maybeToAtom :: Ord a => a -> Atom a (Maybe Int)
- empty :: Ord a => AtomTable a
- evalAtom :: Ord a => Atom a t -> t
- runAtom :: Ord a => Atom a t -> AtomTable a -> (t, AtomTable a)
- mapping :: Ord a => AtomTable a -> Map a Int
Documentation
AtomTable
holds the state necessary for converting to and from
Int
s.
Atom
is a specialized state monad for converting to and from
Int
s.
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
evalAtom :: Ord a => Atom a t -> tSource
evalAtom c
runs computation c in the Atom monad with the empty
initial AtomTable
.