parameterized-utils-1.0.0: Classes and data structures for working with data-kind indexed types

Copyright(c) Galois Inc 2014-2016
MaintainerJoe Hendrix <jhendrix@galois.com>
Safe HaskellTrustworthy
LanguageHaskell98

Data.Parameterized.Nonce

Contents

Description

This module provides a simple generator of new indexes in the ST monad. It is predictable and not intended for cryptographic purposes.

This module also provides a global nonce generator that will generate 2^64 nonces before looping.

NOTE: The TestEquality and OrdF instances for the Nonce type simply compare the generated nonce values and then assert to the compiler (via unsafeCoerce) that the types ascribed to the nonces are equal if their values are equal.

Synopsis

NonceGenerator

data NonceGenerator (m :: * -> *) (s :: *) Source #

Provides a monadic action for getting fresh typed names.

The first type parameter m is the monad used for generating names, and the second parameter s is used for the counter.

freshNonce :: NonceGenerator m s -> forall k (tp :: k). m (Nonce s tp) Source #

data Nonce (s :: *) (tp :: k) Source #

An index generated by the counter.

Instances

TestEquality k (Nonce k s) Source # 

Methods

testEquality :: f a -> f b -> Maybe ((Nonce k s :~: a) b) #

HashableF k (Nonce k s) Source # 

Methods

hashWithSaltF :: Int -> f tp -> Int Source #

hashF :: f tp -> Int Source #

ShowF k (Nonce k s) Source # 

Methods

withShow :: p f -> q tp -> (Show (f tp) -> a) -> a Source #

showF :: f tp -> String Source #

showsF :: f tp -> String -> String Source #

OrdF k (Nonce k s) Source # 

Methods

compareF :: ktp x -> ktp y -> OrderingF (Nonce k s) x y Source #

leqF :: ktp x -> ktp y -> Bool Source #

ltF :: ktp x -> ktp y -> Bool Source #

geqF :: ktp x -> ktp y -> Bool Source #

gtF :: ktp x -> ktp y -> Bool Source #

Eq (Nonce k s tp) Source # 

Methods

(==) :: Nonce k s tp -> Nonce k s tp -> Bool #

(/=) :: Nonce k s tp -> Nonce k s tp -> Bool #

Ord (Nonce k s tp) Source # 

Methods

compare :: Nonce k s tp -> Nonce k s tp -> Ordering #

(<) :: Nonce k s tp -> Nonce k s tp -> Bool #

(<=) :: Nonce k s tp -> Nonce k s tp -> Bool #

(>) :: Nonce k s tp -> Nonce k s tp -> Bool #

(>=) :: Nonce k s tp -> Nonce k s tp -> Bool #

max :: Nonce k s tp -> Nonce k s tp -> Nonce k s tp #

min :: Nonce k s tp -> Nonce k s tp -> Nonce k s tp #

Show (Nonce k s tp) Source # 

Methods

showsPrec :: Int -> Nonce k s tp -> ShowS #

show :: Nonce k s tp -> String #

showList :: [Nonce k s tp] -> ShowS #

Hashable (Nonce k s tp) Source # 

Methods

hashWithSalt :: Int -> Nonce k s tp -> Int #

hash :: Nonce k s tp -> Int #

Accessing a nonce generator

newSTNonceGenerator :: ST t (Some (NonceGenerator (ST t))) Source #

Create a new nonce generator in the ST monad.

newIONonceGenerator :: IO (Some (NonceGenerator IO)) Source #

Create a new nonce generator in the ST monad.

withIONonceGenerator :: (forall s. NonceGenerator IO s -> IO r) -> IO r Source #

Create a new nonce generator in the IO monad.

withSTNonceGenerator :: (forall s. NonceGenerator (ST t) s -> ST t r) -> ST t r Source #

Run a ST computation with a new nonce generator in the ST monad.

withGlobalSTNonceGenerator :: (forall t. NonceGenerator (ST t) t -> ST t r) -> r Source #

Create a new counter.

globalNonceGenerator :: NonceGenerator IO GlobalNonceGenerator Source #

A nonce generator that uses a globally-defined counter.