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

Copyright | (c) Galois Inc 2014
Maintainer | Joe Hendrix <jhendrix@galois.com>
Stability | provisional
Safe Haskell | Unsafe
Language | Haskell2010

Data.Parameterized.Nonce.Unsafe

Description

Deprecated: Migrate to use Data.Parameterized.Nonce instead, this module will be removed soon.

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

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. This is only OK because of the discipline by which nonces should be used: they should only be generated from a `NonceGenerator` (i.e., should not be built directly), and nonces from different generators must never be compared! Arranging to compare Nonces from different origins would allow users to build `unsafeCoerce` via the `testEquality` function.

This module is deprecated, and should not be used in new code. Clients of this module should migrate to use Data.Parameterized.Nonce.

Synopsis

- data NonceGenerator s
- newNonceGenerator :: ST s (NonceGenerator s)
- freshNonce :: forall {k} s (tp :: k). NonceGenerator s -> ST s (Nonce tp)
- atLimit :: NonceGenerator s -> ST s Bool
- data Nonce (tp :: k)
- indexValue :: Nonce tp -> Word64

# Documentation

data NonceGenerator s Source #

A simple type that for getting fresh indices in the `ST` monad. The type parameter `s` is used for the `ST` monad parameter.

newNonceGenerator :: ST s (NonceGenerator s) Source #

Create a new counter.

freshNonce :: forall {k} s (tp :: k). NonceGenerator s -> ST s (Nonce tp) Source #

Get a fresh index and increment the counter.

atLimit :: NonceGenerator s -> ST s Bool Source #

Return true if counter has reached the limit, and can't be incremented without risk of error.

data Nonce (tp :: k) Source #

An index generated by the counter.

#### Instances

Instances details

TestEquality (Nonce :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods testEquality :: forall (a :: k) (b :: k). Nonce a -> Nonce b -> Maybe (a :~: b) Source #
EqF (Nonce :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods eqF :: forall (a :: k). Nonce a -> Nonce a -> Bool Source #
HashableF (Nonce :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods hashWithSaltF :: forall (tp :: k). Int -> Nonce tp -> Int Source # hashF :: forall (tp :: k). Nonce tp -> Int Source #
OrdF (Nonce :: k -> Type) Source # |

Instance details

Defined in Data.Parameterized.Nonce.Unsafe

Methods

compareF :: forall (x :: k) (y :: k). Nonce x -> Nonce y -> OrderingF x y Source #

leqF :: forall (x :: k) (y :: k). Nonce x -> Nonce y -> Bool Source #

ltF :: forall (x :: k) (y :: k). Nonce x -> Nonce y -> Bool Source #

geqF :: forall (x :: k) (y :: k). Nonce x -> Nonce y -> Bool Source #

gtF :: forall (x :: k) (y :: k). Nonce x -> Nonce y -> Bool Source #

ShowF (Nonce :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods withShow :: forall p q (tp :: k) a. p (Nonce :: k -> Type) -> q tp -> (Show (Nonce tp) => a) -> a Source # showF :: forall (tp :: k). Nonce tp -> String Source # showsPrecF :: forall (tp :: k). Int -> Nonce tp -> String -> String Source #
Show (Nonce tp) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods showsPrec :: Int -> Nonce tp -> ShowS Source # show :: Nonce tp -> String Source # showList :: [Nonce tp] -> ShowS Source #
Eq (Nonce tp) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods (==) :: Nonce tp -> Nonce tp -> Bool Source # (/=) :: Nonce tp -> Nonce tp -> Bool Source #
Ord (Nonce tp) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods compare :: Nonce tp -> Nonce tp -> Ordering Source # (<) :: Nonce tp -> Nonce tp -> Bool Source # (<=) :: Nonce tp -> Nonce tp -> Bool Source # (>) :: Nonce tp -> Nonce tp -> Bool Source # (>=) :: Nonce tp -> Nonce tp -> Bool Source # max :: Nonce tp -> Nonce tp -> Nonce tp Source # min :: Nonce tp -> Nonce tp -> Nonce tp Source #
Hashable (Nonce tp) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods hashWithSalt :: Int -> Nonce tp -> Int Source # hash :: Nonce tp -> Int Source #

indexValue :: Nonce tp -> Word64 Source #