-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A monad for using CryptoRandomGen
--   
--   A monad for using CryptoRandomGen
@package monadcryptorandom
@version 0.5.3


-- | Much like the <a>MonadRandom</a> package
--   (<a>Control.Monad.Random</a>), this module provides plumbing for the
--   CryptoRandomGen generators.
module Control.Monad.CryptoRandom

-- | <tt>CRandom a</tt> is much like the <tt>Random</tt> class from the
--   <a>System.Random</a> module in the <a>random</a> package. The main
--   difference is CRandom builds on <a>crypto-api</a>'s
--   <a>CryptoRandomGen</a>, so it allows explicit failure.
--   
--   <tt>crandomR (low,high) g</tt> as typically instantiated will generate
--   a value between [low, high] inclusively, swapping the pair if high
--   &lt; low.
--   
--   Provided instances for <tt>crandom g</tt> generates randoms between
--   the bounds and between +/- 2^256 for Integer.
--   
--   The <a>crandomR</a> function has degraded (theoretically unbounded,
--   probabilistically decent) performance the closer your range size (high
--   - low) is to 2^n (from the top).
class CRandom a where crandoms g = case crandom g of { Left _ -> [] Right (a, g') -> a : crandoms g' }
crandom :: (CRandom a, CryptoRandomGen g) => g -> Either GenError (a, g)
crandoms :: (CRandom a, CryptoRandomGen g) => g -> [a]
class CRandomR a where crandomRs r g = case crandomR r g of { Left _ -> [] Right (a, g') -> a : crandomRs r g' }
crandomR :: (CRandomR a, CryptoRandomGen g) => (a, a) -> g -> Either GenError (a, g)
crandomRs :: (CRandomR a, CryptoRandomGen g) => (a, a) -> g -> [a]

-- | <tt>MonadCRandom m</tt> represents a monad that can produce random
--   values (or fail with a <a>GenError</a>). It is suggested you use the
--   <a>CRandT</a> transformer in your monad stack.
class (ContainsGenError e, MonadError e m) => MonadCRandom e m
getCRandom :: (MonadCRandom e m, CRandom a) => m a
getBytes :: MonadCRandom e m => Int -> m ByteString
getBytesWithEntropy :: MonadCRandom e m => Int -> ByteString -> m ByteString
doReseed :: MonadCRandom e m => ByteString -> m ()
class (ContainsGenError e, MonadError e m) => MonadCRandomR e m
getCRandomR :: (MonadCRandomR e m, CRandomR a) => (a, a) -> m a
class ContainsGenError e
toGenError :: ContainsGenError e => e -> Maybe GenError
fromGenError :: ContainsGenError e => GenError -> e

-- | CRandT is the transformer suggested for MonadCRandom.
data CRandT g e m a

-- | Simple users of generators can use CRand for quick and easy generation
--   of randoms. See below for a simple use of <a>newGenIO</a> (from
--   <a>crypto-api</a>), <a>getCRandom</a>, <a>getBytes</a>, and
--   <tt>runCRandom</tt>.
--   
--   <pre>
--   getRandPair = do
--      int &lt;- getCRandom
--      bytes &lt;- getBytes 100
--      return (int, bytes)
--   
--   func = do
--      g &lt;- newGenIO
--      case runCRand getRandPair g of
--          Right ((int,bytes), g') -&gt; useRandomVals (int,bytes)
--          Left x -&gt; handleGenError x
--   </pre>
type CRand g e = CRandT g e Identity
runCRandT :: ContainsGenError e => CRandT g e m a -> g -> m (Either e (a, g))
evalCRandT :: (ContainsGenError e, Monad m) => CRandT g e m a -> g -> m (Either e a)
runCRand :: CRand g GenError a -> g -> Either GenError (a, g)
evalCRand :: CRand g GenError a -> g -> Either GenError a
newGenCRand :: (CryptoRandomGen g, MonadCRandom GenError m, Functor m) => m g
instance (Monad m, Error e) => MonadError e (CRandT g e m)
instance (Monad m, Error e) => Monad (CRandT g e m)
instance (MonadIO m, Error e) => MonadIO (CRandT g e m)
instance Functor m => Functor (CRandT g e m)
instance (MonadFix m, Error e) => MonadFix (CRandT g e m)
instance Error GenError
instance (MonadCRandomR e m, Monoid w) => MonadCRandomR e (RWST r w s m)
instance (MonadCRandomR e m, Monoid w) => MonadCRandomR e (RWST r w s m)
instance MonadCRandomR e m => MonadCRandomR e (ReaderT r m)
instance (MonadCRandomR e m, Monoid w) => MonadCRandomR e (WriterT w m)
instance (MonadCRandomR e m, Monoid w) => MonadCRandomR e (WriterT w m)
instance MonadCRandomR e m => MonadCRandomR e (StateT s m)
instance MonadCRandomR e m => MonadCRandomR e (StateT s m)
instance (ContainsGenError e, Error e, Monad m, CryptoRandomGen g) => MonadCRandomR e (CRandT g e m)
instance (ContainsGenError e, Error e, Monad m, CryptoRandomGen g) => MonadCRandom e (CRandT g e m)
instance (MonadCont m, Error e) => MonadCont (CRandT g e m)
instance (MonadWriter w m, Error e) => MonadWriter w (CRandT g e m)
instance (MonadReader r m, Error e) => MonadReader r (CRandT g e m)
instance (MonadState s m, Error e) => MonadState s (CRandT g e m)
instance Error e => MonadTrans (CRandT g e)
instance (Functor m, Monad m, Error e) => Applicative (CRandT g e m)
instance CRandom Bool
instance CRandomR Int64
instance CRandom Int64
instance CRandomR Int32
instance CRandom Int32
instance CRandomR Int16
instance CRandom Int16
instance CRandomR Int8
instance CRandom Int8
instance CRandomR Word64
instance CRandom Word64
instance CRandomR Word32
instance CRandom Word32
instance CRandomR Word16
instance CRandom Word16
instance CRandomR Word8
instance CRandom Word8
instance CRandomR Int
instance CRandom Int
instance CRandomR Integer
instance ContainsGenError GenError
instance (Monoid w, MonadCRandom e m) => MonadCRandom e (RWST r w s m)
instance (Monoid w, MonadCRandom e m) => MonadCRandom e (RWST r w s m)
instance MonadCRandom e m => MonadCRandom e (ReaderT r m)
instance (Monoid w, MonadCRandom e m) => MonadCRandom e (WriterT w m)
instance (Monoid w, MonadCRandom e m) => MonadCRandom e (WriterT w m)
instance MonadCRandom e m => MonadCRandom e (StateT s m)
instance MonadCRandom e m => MonadCRandom e (StateT s m)
