ouroboros-consensus-0.21.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Ouroboros.Consensus.ChainGenerator.Counting

Description

Very strong types for working with indices, counts, etc within sequences.

Synopsis

general counts

newtype Count (base ∷ Type) (elem ∷ kelem) (which ∷ kwhich) Source #

A type-indexed Int to represent counts of elements in containers

  • base is the type-level name of the container in which we are counting (e.g. Win (Lbl HonestLbl) skolem1)
  • elem is the type-level name of the elements in the container (e.g. SlotE)
  • which is the type-level name of some property that identifies the particular elements that we are counting (e.g. Pred, Total, or Other)

TODO: rename base to container

Constructors

Count Int 

Instances

Instances details
Arbitrary (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

arbitraryGen (Count base elem which) Source #

shrinkCount base elem which → [Count base elem which] Source #

which ~~ OtherEnum (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

succCount base elem which → Count base elem which #

predCount base elem which → Count base elem which #

toEnumIntCount base elem which #

fromEnumCount base elem which → Int #

enumFromCount base elem which → [Count base elem which] #

enumFromThenCount base elem which → Count base elem which → [Count base elem which] #

enumFromToCount base elem which → Count base elem which → [Count base elem which] #

enumFromThenToCount base elem which → Count base elem which → Count base elem which → [Count base elem which] #

which ~~ OtherNum (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

(+)Count base elem which → Count base elem which → Count base elem which #

(-)Count base elem which → Count base elem which → Count base elem which #

(*)Count base elem which → Count base elem which → Count base elem which #

negateCount base elem which → Count base elem which #

absCount base elem which → Count base elem which #

signumCount base elem which → Count base elem which #

fromIntegerIntegerCount base elem which #

Read (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

readsPrecIntReadS (Count base elem which) #

readListReadS [Count base elem which] #

readPrecReadPrec (Count base elem which) #

readListPrecReadPrec [Count base elem which] #

Show (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

showsPrecIntCount base elem which → ShowS #

showCount base elem which → String #

showList ∷ [Count base elem which] → ShowS #

Eq (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

(==)Count base elem which → Count base elem which → Bool #

(/=)Count base elem which → Count base elem which → Bool #

Ord (Count base elem which) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

compareCount base elem which → Count base elem which → Ordering #

(<)Count base elem which → Count base elem which → Bool #

(<=)Count base elem which → Count base elem which → Bool #

(>)Count base elem which → Count base elem which → Bool #

(>=)Count base elem which → Count base elem which → Bool #

maxCount base elem which → Count base elem which → Count base elem which #

minCount base elem which → Count base elem which → Count base elem which #

forgetBaseCount base elem which → Forgotten (Count () elem which) Source #

forgetElemCount base elem which → Forgotten (Count base () which) Source #

getCountCount base elem which → Int Source #

(+)Count base elem which → IntCount base elem which infixl 6 Source #

(-)Count base elem which → IntCount base elem which infixl 6 Source #

indices and sizes

type Index base elem = Count base elem Preds Source #

data Preds Source #

Type-level name for counting elements with an index smaller than a given value

type Size base elem = Count base elem Total Source #

data Total Source #

Type-level name for counting all elements in a container

forRange_Applicative f ⇒ Size base elem → (Index base elem → f a) → f () Source #

lastIndexSize base elem → Index base elem Source #

The Index of the rightmost element in the sequence of the given Size

rangeSize base elem → [Index base elem] Source #

uniformIndexStatefulGen g m ⇒ Size base elem → g → m (Index base elem) Source #

windows

data Contains (elem ∷ kelem) (outer ∷ Type) (inner ∷ Type) Source #

Values of this type describe a window in a sequence of elements.

A window is an infix of the sequence, and it is described with an offset and a length or size (the number of elements in the window).

  • elem is a type-level name of the elements in the containing sequence (e.g. SlotE)
  • outer is a type-level name identifying the containing sequence (e.g. Win (Lbl HonestLbl) skolem1)
  • inner is a type-level name for the window that the value describes (e.g. Win (Lbl ScgLbl) skolem2)

Note that nothing is said about the containing sequence other than its type name.

TODO: rename Contains to Window

Constructors

UnsafeContains 

Fields

  • !(Index outer elem)

    index of the start of the window as an offset in the containing sequence.

  • !(Size inner elem)

    size of the window INVARIANT: does not reach past the end of the containing sequence (whatever that end is)

Bundled Patterns

pattern ContainsIndex outer elem → Size inner elem → Contains elem outer inner 

Instances

Instances details
Read (Contains elem outer inner) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

readsPrecIntReadS (Contains elem outer inner) #

readListReadS [Contains elem outer inner] #

readPrecReadPrec (Contains elem outer inner) #

readListPrecReadPrec [Contains elem outer inner] #

Show (Contains elem outer inner) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

showsPrecIntContains elem outer inner → ShowS #

showContains elem outer inner → String #

showList ∷ [Contains elem outer inner] → ShowS #

Eq (Contains elem outer inner) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

(==)Contains elem outer inner → Contains elem outer inner → Bool #

(/=)Contains elem outer inner → Contains elem outer inner → Bool #

data Lbl lbl Source #

A human-readable label for a Win

Constructors

Lbl 

Instances

Instances details
lbl ~~ s ⇒ IsLabel s (Lbl lbl) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

fromLabelLbl lbl #

data SomeWindow (lbl ∷ klbl) (outer ∷ Type) (elem ∷ kelem) Source #

Constructors

∀ (skolem ∷ Type). SomeWindow !(Proxy skolem) !(Contains elem outer (Win lbl skolem)) 

Instances

Instances details
Read (SomeWindow lbl outer elem) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

readsPrecIntReadS (SomeWindow lbl outer elem) #

readListReadS [SomeWindow lbl outer elem] #

readPrecReadPrec (SomeWindow lbl outer elem) #

readListPrecReadPrec [SomeWindow lbl outer elem] #

Show (SomeWindow lbl outer elem) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

showsPrecIntSomeWindow lbl outer elem → ShowS #

showSomeWindow lbl outer elem → String #

showList ∷ [SomeWindow lbl outer elem] → ShowS #

Eq (SomeWindow lbl outer elem) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

(==)SomeWindow lbl outer elem → SomeWindow lbl outer elem → Bool #

(/=)SomeWindow lbl outer elem → SomeWindow lbl outer elem → Bool #

data Win (lbl ∷ klbl) (skolem ∷ Type) Source #

A type-level name for a window within some containing sequence

  • lbl is a name component that can be used in multiple names
  • skolem is a component to differentiate between names which use the same lbl

TODO: rename Win to WinLabel

forgetWindowContains elem outer inner → Forgotten (Index outer elem, Index outer elem) Source #

fromWindowContains elem outer inner → Index inner elem → Index outer elem Source #

Converts an index of a window into an index in the containing sequence.

fromWindowVarContains elem outer inner → Var inner x → Var outer x Source #

Converts a count of elements in a window to a count of elements in the containing sequence.

joinWinContains elem outer mid → Contains elem mid inner → Contains elem outer inner Source #

toWindowContains elem outer inner → Index outer elem → Maybe (Index inner elem) Source #

toWindowVarContains elem outer inner → Var outer x → Var inner x Source #

truncateWinContains elem outer inner → Size inner elem → Contains elem outer inner Source #

windowLastContains elem outer inner → Index outer elem Source #

windowSizeContains elem outer inner → Size inner elem Source #

windowStartContains elem outer inner → Index outer elem Source #

withSuffixWindowSize outer elem → Lbl lbl → Index outer elem → SomeWindow lbl outer elem Source #

withSuffixWindow outerSz lbl i is the window between indices i and the end of the containing sequence of length outerSz with name lbl.

withTopWindowLbl lbl → Int → (∀ base. Proxy base → SomeWindow lbl base elem → ans) → ans Source #

withTopWindow lbl sz k passes to k a window of size sz with name lbl at offset 0 of some containing sequence with a unique name base.

withWindowSize outer elem → Lbl lbl → Index outer elem → Size x elem → SomeWindow lbl outer elem Source #

withWindow outerSz lbl offset innerSz is a window of length innerSz with name lbl starting at offset in a sequence with length outerSz.

If the window doesn't fit in the containing sequence, it is clipped so the resulting (possibly empty) window is contained.

Note that the window can spill either on the right if i + innerSz > outerSz, or it can spill on the left if i < 0, or it can spill on both sides simultaneously.

withWindowBetweenSize outer elem → Lbl lbl → Index outer elem → Index outer elem → SomeWindow lbl outer elem Source #

withWindowBetween outerSz lbl i j is the window between indices i and j with name lbl in a containing sequence of length outerSz.

vectors

newtype MVector base elem s a Source #

A type-indexed vector carrying values of a container

  • base is a type-level name identifying the container (e.g. Win (Lbl HonestLbl) skolem1)
  • elem is a type-level name of the elements in the container (e.g. SlotE)

Constructors

MVector (MVector s a) 

newtype Vector base elem a Source #

Same indices as Index and Size

Constructors

Vector (Vector a) 

Instances

Instances details
(Arbitrary a, Unbox a) ⇒ Arbitrary (Vector base elem a) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

arbitraryGen (Vector base elem a) Source #

shrinkVector base elem a → [Vector base elem a] Source #

(Read a, Unbox a) ⇒ Read (Vector base elem a) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

readsPrecIntReadS (Vector base elem a) #

readListReadS [Vector base elem a] #

readPrecReadPrec (Vector base elem a) #

readListPrecReadPrec [Vector base elem a] #

(Show a, Unbox a) ⇒ Show (Vector base elem a) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

showsPrecIntVector base elem a → ShowS #

showVector base elem a → String #

showList ∷ [Vector base elem a] → ShowS #

(Unbox a, Eq a) ⇒ Eq (Vector base elem a) Source # 
Instance details

Defined in Test.Ouroboros.Consensus.ChainGenerator.Counting

Methods

(==)Vector base elem a → Vector base elem a → Bool #

(/=)Vector base elem a → Vector base elem a → Bool #

createVUnbox a ⇒ (∀ s. ST s (MVector base elem s a)) → Vector base elem a Source #

getMVectorMVector base elem s a → MVector s a Source #

getVectorVector base elem a → Vector a Source #

lengthMVUnbox a ⇒ MVector base elem s a → Size base elem Source #

lengthVUnbox a ⇒ Vector base elem a → Size base elem Source #

modifyMVUnbox a ⇒ MVector base elem s a → (a → a) → Index base elem → ST s () Source #

readMVUnbox a ⇒ MVector base elem s a → Index base elem → ST s a Source #

readVUnbox a ⇒ Vector base elem a → Index base elem → a Source #

replicateMVUnbox a ⇒ Size base elem → ST s a → ST s (MVector base elem s a) Source #

sliceMVUnbox a ⇒ Contains elem outer inner → MVector outer elem s a → MVector inner elem s a Source #

sliceVUnbox a ⇒ Contains elem outer inner → Vector outer elem a → Vector inner elem a Source #

unsafeThawVUnbox a ⇒ Vector base elem a → ST s (MVector base elem s a) Source #

writeMVUnbox a ⇒ MVector base elem s a → Index base elem → a → ST s () Source #

variables

data Other Source #

A type-level name for counting elements without a specific property

type Var base elem = Count base elem Other Source #

joinVarMVector base elem s a → Var a x → Var base x Source #

A count of things in an element can be lifted to a count of things in a vector

toIndexVar base elem → Index base elem Source #

When the Var has become a Index

toSizeVar base elem → Size base elem Source #

When the Var has become a Size

toVarCount base elem which → Var base elem Source #

For initializing a Var