plutus-core-1.54.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusCore.Flat.Instances.Mono

Synopsis

Documentation

sizeSequence ∷ (IsSequence mono, Flat (Element mono)) ⇒ mono → NumBitsNumBits Source #

Calculate size of an instance of IsSequence as the sum:

  • of the size of all the elements
  • plus the size of the array constructors (1 byte every 255 elements plus one final byte)

encodeSequence ∷ (Flat (Element mono), MonoFoldable mono) ⇒ mono → Encoding Source #

Encode an instance of IsSequence, as an array

decodeSequence ∷ (Flat (Element b), IsSequence b) ⇒ Get b Source #

Decode an instance of IsSequence, as an array

sizeList ∷ (MonoFoldable mono, Flat (Element mono)) ⇒ mono → NumBitsNumBits Source #

encodeList ∷ (Flat (Element mono), MonoFoldable mono) ⇒ mono → Encoding Source #

sizeSet ∷ (IsSet set, Flat (Element set)) ⇒ Size set Source #

encodeSet ∷ (IsSet set, Flat (Element set)) ⇒ set → Encoding Source #

decodeSet ∷ (IsSet set, Flat (Element set)) ⇒ Get set Source #

encodeMap ∷ (Flat (ContainerKey map), Flat (MapValue map), IsMap map) ⇒ map → Encoding Source #

Encode an instance of IsMap, as a list of (Key,Value) tuples

decodeMap ∷ (Flat (ContainerKey map), Flat (MapValue map), IsMap map) ⇒ Get map Source #

Decode an instance of IsMap, as a list of (Key,Value) tuples

newtype AsArray a Source #

Sequences are defined as Arrays:

Array v = A0 | A1 v (Array v) | A2 v v (Array v) ... | A255 ... (Array v)

In practice, this means that the sequence is encoded as a sequence of blocks of up to 255 elements, with every block preceded by the count of the elements in the block and a final 0-length block.

Lists are defined as:

List a ≡ Nil | Cons a (List a)

In practice, this means that the list elements will be prefixed with a 1 bit and followed by a final 0 bit.

The AsList/AsArray wrappers can be used to serialise sequences as Lists or Arrays.

Let's see some examples.

>>> flatBits $ AsList [True,True,True]
"1111110"

So we have Cons True (11) repeated three times, followed by a final Nil (0).

The list encoding is the default one for lists so AsList is in this case unnecessary:

>>> flatBits $ [True,True,True]
"1111110"

We can force a list to be encoded as an Array with AsArray:

>>> flatBits $ AsArray [True,True,True]
"00000011 11100000 000"

We have the initial block with a count of 3 (3 == 00000011) followed by the elements True True True (111) and then the final block of 0 elements ("00000 000").

>>> flatBits $ [AsArray [True,True,True]]
"10000001 11110000 00000"
>>> flatBits $ (True,True,True,AsArray $ replicate 7 True)
"11100000 11111111 11000000 00"
>>> flatBits $ AsArray ([]::[()])
"00000000"
>>> flatBits $ AsList ([]::[()])
"0"
>>> tst (AsList [11::Word8,22,33])
(True,28,[133,197,164,32])
>>> tst (AsSet (Data.Set.fromList [11::Word8,22,33]))
(True,28,[133,197,164,32])
>>> tst [AsArray [1..3], AsArray [4..8]]
(True,99,[129,129,2,3,0,65,66,2,131,3,132,0,0])
>>> tst $ [AsArray [(1::Word8)..3], AsArray [4..8]]
(True,99,[129,128,129,1,128,65,65,1,65,129,194,0,0])
>>> tst $ [AsArray [(1::Int)..3]]
(True,42,[129,129,2,3,0,0])

Constructors

AsArray 

Fields

Instances

Instances details
Show a ⇒ Show (AsArray a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

showsPrecIntAsArray a → ShowS Source #

showAsArray a → String Source #

showList ∷ [AsArray a] → ShowS Source #

Eq a ⇒ Eq (AsArray a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

(==)AsArray a → AsArray a → Bool Source #

(/=)AsArray a → AsArray a → Bool Source #

Ord a ⇒ Ord (AsArray a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

compareAsArray a → AsArray a → Ordering Source #

(<)AsArray a → AsArray a → Bool Source #

(<=)AsArray a → AsArray a → Bool Source #

(>)AsArray a → AsArray a → Bool Source #

(>=)AsArray a → AsArray a → Bool Source #

maxAsArray a → AsArray a → AsArray a Source #

minAsArray a → AsArray a → AsArray a Source #

(IsSequence r, Flat (Element r)) ⇒ Flat (AsArray r) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

newtype AsList a Source #

Constructors

AsList 

Fields

Instances

Instances details
Show a ⇒ Show (AsList a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

showsPrecIntAsList a → ShowS Source #

showAsList a → String Source #

showList ∷ [AsList a] → ShowS Source #

Eq a ⇒ Eq (AsList a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

(==)AsList a → AsList a → Bool Source #

(/=)AsList a → AsList a → Bool Source #

Ord a ⇒ Ord (AsList a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

compareAsList a → AsList a → Ordering Source #

(<)AsList a → AsList a → Bool Source #

(<=)AsList a → AsList a → Bool Source #

(>)AsList a → AsList a → Bool Source #

(>=)AsList a → AsList a → Bool Source #

maxAsList a → AsList a → AsList a Source #

minAsList a → AsList a → AsList a Source #

(IsSequence l, Flat (Element l)) ⇒ Flat (AsList l) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

newtype AsSet a Source #

Sets are saved as lists of values.

>>> tstBits $ AsSet (Data.Set.fromList ([False,True,False]::[Bool]))
(True,5,"10110")

Constructors

AsSet 

Fields

Instances

Instances details
Show a ⇒ Show (AsSet a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

showsPrecIntAsSet a → ShowS Source #

showAsSet a → String Source #

showList ∷ [AsSet a] → ShowS Source #

Eq a ⇒ Eq (AsSet a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

(==)AsSet a → AsSet a → Bool Source #

(/=)AsSet a → AsSet a → Bool Source #

Ord a ⇒ Ord (AsSet a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

compareAsSet a → AsSet a → Ordering Source #

(<)AsSet a → AsSet a → Bool Source #

(<=)AsSet a → AsSet a → Bool Source #

(>)AsSet a → AsSet a → Bool Source #

(>=)AsSet a → AsSet a → Bool Source #

maxAsSet a → AsSet a → AsSet a Source #

minAsSet a → AsSet a → AsSet a Source #

(IsSet set, Flat (Element set)) ⇒ Flat (AsSet set) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

encodeAsSet set → Encoding Source #

decodeGet (AsSet set) Source #

sizeAsSet set → NumBitsNumBits Source #

newtype AsMap a Source #

Maps are saved as lists of (key,value) tuples.

>>> tst (AsMap (Data.Map.fromList ([]::[(Word8,())])))
(True,1,[0])
>>> tst (AsMap (Data.Map.fromList [(3::Word,9::Word)]))
(True,18,[129,132,128])

Constructors

AsMap 

Fields

Instances

Instances details
Show a ⇒ Show (AsMap a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

showsPrecIntAsMap a → ShowS Source #

showAsMap a → String Source #

showList ∷ [AsMap a] → ShowS Source #

Eq a ⇒ Eq (AsMap a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

(==)AsMap a → AsMap a → Bool Source #

(/=)AsMap a → AsMap a → Bool Source #

Ord a ⇒ Ord (AsMap a) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

compareAsMap a → AsMap a → Ordering Source #

(<)AsMap a → AsMap a → Bool Source #

(<=)AsMap a → AsMap a → Bool Source #

(>)AsMap a → AsMap a → Bool Source #

(>=)AsMap a → AsMap a → Bool Source #

maxAsMap a → AsMap a → AsMap a Source #

minAsMap a → AsMap a → AsMap a Source #

(IsMap map, Flat (ContainerKey map), Flat (MapValue map)) ⇒ Flat (AsMap map) Source # 
Instance details

Defined in PlutusCore.Flat.Instances.Mono

Methods

encodeAsMap map → Encoding Source #

decodeGet (AsMap map) Source #

sizeAsMap map → NumBitsNumBits Source #