Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
MemoBytes is an abstraction for a data type that encodes its own serialization.
The idea is to use a newtype around a MemoBytes applied to a non-memoizing type.
For example: newtype Foo = Foo (MemoBytes
NonMemoizingFoo)
This way all the instances for Foo (
can be derived for free. MemoBytes plays an important role in the Eq
, Show
, EncCBOR
, DecCBOR
, NoThunks
, Generic`)SafeToHash
class
introduced in the module SafeHash
Synopsis
- data MemoBytes t era where
- pattern Memo ∷ Era era ⇒ t era → ShortByteString → MemoBytes t era
- type family MemoHashIndex (t ∷ Type → Type) ∷ Type
- type Mem t era = Annotator (MemoBytes t era)
- mkMemoBytes ∷ ∀ era t. Era era ⇒ t era → ByteString → MemoBytes t era
- getMemoBytesType ∷ MemoBytes t era → t era
- getMemoBytesHash ∷ MemoBytes t era → SafeHash (EraCrypto era) (MemoHashIndex t)
- memoBytes ∷ ∀ era w t. Era era ⇒ Encode w (t era) → MemoBytes t era
- shorten ∷ ByteString → ShortByteString
- showMemo ∷ Show (t era) ⇒ MemoBytes t era → String
- printMemo ∷ Show (t era) ⇒ MemoBytes t era → IO ()
- shortToLazy ∷ ShortByteString → ByteString
- contentsEq ∷ Eq (t era) ⇒ MemoBytes t era → MemoBytes t era → Bool
- class Memoized t where
- mkMemoized ∷ ∀ era t. (Era era, EncCBOR (RawType t era), Memoized t) ⇒ RawType t era → t era
- decodeMemoized ∷ Era era ⇒ Decoder s (t era) → Decoder s (MemoBytes t era)
- getMemoSafeHash ∷ Memoized t ⇒ t era → SafeHash (EraCrypto era) (MemoHashIndex (RawType t))
- getMemoRawType ∷ Memoized t ⇒ t era → RawType t era
- zipMemoRawType ∷ (Memoized t1, Memoized t2) ⇒ (RawType t1 era → RawType t2 era → a) → t1 era → t2 era → a
- eqRawType ∷ ∀ t era. (Memoized t, Eq (RawType t era)) ⇒ t era → t era → Bool
- getMemoRawBytes ∷ Memoized t ⇒ t era → ShortByteString
- lensMemoRawType ∷ (Era era, EncCBOR (RawType t era), Memoized t) ⇒ (RawType t era → a) → (RawType t era → b → RawType t era) → Lens (t era) (t era) a b
- getterMemoRawType ∷ Memoized t ⇒ (RawType t era → a) → SimpleGetter (t era) a
- class EqRaw a where
Documentation
data MemoBytes t era where Source #
Pair together a type t
and its serialization. Used to encode a type
that is serialized over the network, and to remember the original bytes
that were used to transmit it. Important since hashes are computed
from the serialization of a type, and EncCBOR instances do not have unique
serializations.
pattern Memo ∷ Era era ⇒ t era → ShortByteString → MemoBytes t era |
Instances
type family MemoHashIndex (t ∷ Type → Type) ∷ Type Source #
Instances
type MemoHashIndex PlutusData Source # | |
Defined in Cardano.Ledger.Plutus.Data |
type Mem t era = Annotator (MemoBytes t era) Source #
Useful when deriving DecCBOR(Annotator T) deriving via (Mem T) instance (Era era) => DecCBOR (Annotator T)
mkMemoBytes ∷ ∀ era t. Era era ⇒ t era → ByteString → MemoBytes t era Source #
Smart constructor
getMemoBytesType ∷ MemoBytes t era → t era Source #
Extract the inner type of the MemoBytes
getMemoBytesHash ∷ MemoBytes t era → SafeHash (EraCrypto era) (MemoHashIndex t) Source #
Extract the hash value of the binary representation of the MemoBytes
memoBytes ∷ ∀ era w t. Era era ⇒ Encode w (t era) → MemoBytes t era Source #
Create MemoBytes from its CBOR encoding
shorten ∷ ByteString → ShortByteString Source #
Turn a lazy bytestring into a short bytestring.
showMemo ∷ Show (t era) ⇒ MemoBytes t era → String Source #
Turn a MemoBytes into a string, Showing both its internal structure and its original bytes. Useful since the Show instance of MemoBytes does not display the original bytes.
shortToLazy ∷ ShortByteString → ByteString Source #
Helper function. Converts a short bytestring to a lazy bytestring.
contentsEq ∷ Eq (t era) ⇒ MemoBytes t era → MemoBytes t era → Bool Source #
Returns true if the contents of the MemoBytes are equal
Memoized
Class that relates the actual type with its raw and byte representations
mkMemoized ∷ ∀ era t. (Era era, EncCBOR (RawType t era), Memoized t) ⇒ RawType t era → t era Source #
Construct memoized type from the raw type using its EncCBOR instance
getMemoSafeHash ∷ Memoized t ⇒ t era → SafeHash (EraCrypto era) (MemoHashIndex (RawType t)) Source #
Extract memoized SafeHash
getMemoRawType ∷ Memoized t ⇒ t era → RawType t era Source #
Extract the raw type from the memoized version
zipMemoRawType ∷ (Memoized t1, Memoized t2) ⇒ (RawType t1 era → RawType t2 era → a) → t1 era → t2 era → a Source #
This is a helper function that operates on raw types of two memoized types.
getMemoRawBytes ∷ Memoized t ⇒ t era → ShortByteString Source #
Extract the raw bytes from the memoized version
lensMemoRawType ∷ (Era era, EncCBOR (RawType t era), Memoized t) ⇒ (RawType t era → a) → (RawType t era → b → RawType t era) → Lens (t era) (t era) a b Source #
This is a helper Lens creator for any Memoized type.
getterMemoRawType ∷ Memoized t ⇒ (RawType t era → a) → SimpleGetter (t era) a Source #
This is a helper SimpleGetter creator for any Memoized type
Raw equality
Type class that implements equality on the Haskell type, ignoring any of the potentially memoized binary representation of the type.
Nothing
Instances
Crypto c ⇒ EqRaw (BootstrapWitness c) Source # | |
Defined in Cardano.Ledger.Keys.Bootstrap eqRaw ∷ BootstrapWitness c → BootstrapWitness c → Bool Source # | |
(Crypto c, Typeable kr) ⇒ EqRaw (WitVKey kr c) Source # | |