cardano-data-0.1.0.0: Specialized data for Cardano project
Safe Haskell None
Language Haskell2010

Data.Sharing

Synopsis

Documentation

class Monoid ( Share a) => FromSharedCBOR a where Source #

Minimal complete definition

( fromSharedCBOR | fromSharedPlusCBOR )

Associated Types

type Share a :: Type Source #

type Share a = ()

Methods

getShare :: a -> Share a Source #

Whenever fromShareCBOR is being used for defining the instance this function should return the state that can be added whenever user invokes fromSharedPlusCBOR . mempty is returned by default.

fromSharedCBOR :: Share a -> Decoder s a Source #

Utilize sharing when decoding, but do not add anything to the state for future sharing.

fromSharedPlusCBOR :: StateT ( Share a) ( Decoder s) a Source #

Deserialize with sharing and add to the state that is used for sharing. Default implementation will add value returned by getShare for adding to the state.

Instances

Instances details
( Ord k, FromCBOR k, FromCBOR v) => FromSharedCBOR ( Map k v) Source #
Instance details

Defined in Data.Sharing

Associated Types

type Share ( Map k v) Source #

( Ord a, Ord b, FromCBOR a, FromCBOR b) => FromSharedCBOR ( BiMap b a b) Source #
Instance details

Defined in Data.Sharing

Associated Types

type Share ( BiMap b a b) Source #

( FromCBOR coin, Ord ptr, FromCBOR ptr, FromCBOR pool) => FromSharedCBOR ( Trip coin ptr pool) Source #
Instance details

Defined in Data.UMap

Associated Types

type Share ( Trip coin ptr pool) Source #

Methods

getShare :: Trip coin ptr pool -> Share ( Trip coin ptr pool) Source #

fromSharedCBOR :: Share ( Trip coin ptr pool) -> Decoder s ( Trip coin ptr pool) Source #

fromSharedPlusCBOR :: StateT ( Share ( Trip coin ptr pool)) ( Decoder s) ( Trip coin ptr pool) Source #

( Ord k, FromCBOR k, FromCBOR v) => FromSharedCBOR ( VMap VB VB k v) Source #
Instance details

Defined in Data.Sharing

Associated Types

type Share ( VMap VB VB k v) Source #

( Ord k, FromCBOR k, FromCBOR v, Prim v) => FromSharedCBOR ( VMap VB VP k v) Source #
Instance details

Defined in Data.Sharing

Associated Types

type Share ( VMap VB VP k v) Source #

( Ord cred, FromCBOR cred, Ord ptr, FromCBOR ptr, FromCBOR coin, FromCBOR pool) => FromSharedCBOR ( UMap coin cred pool ptr) Source #
Instance details

Defined in Data.UMap

Associated Types

type Share ( UMap coin cred pool ptr) Source #

Methods

getShare :: UMap coin cred pool ptr -> Share ( UMap coin cred pool ptr) Source #

fromSharedCBOR :: Share ( UMap coin cred pool ptr) -> Decoder s ( UMap coin cred pool ptr) Source #

fromSharedPlusCBOR :: StateT ( Share ( UMap coin cred pool ptr)) ( Decoder s) ( UMap coin cred pool ptr) Source #

data Intern a Source #

This is an abstract interface that does the interning. In other words it does the actual sharing by looking up the supplied value in some existing data structure and uses that value instead. Relying on this interface gives us the benefit of ignoring the type of underlying data structure and allows us to compose many Intern s with the monoidal interface provided by Interns wrapper. In order to create an Intern see the internsFromMap or internsFromVMap functions.

Constructors

Intern

Fields

  • internMaybe :: a -> Maybe a

    Function that will do the interning. If value is not available then Nothing is returned.

  • internWeight :: ! Int

    Used for sorting. Normally set to the size of the underlying data structure. Keeping interns sorted with respect to how many elements is in the underlying data structure in theory gives a better chance of successful intern hit sooner rather than later.

fromSharedPlusLensCBOR :: FromSharedCBOR b => Lens' bs ( Share b) -> StateT bs ( Decoder s) b Source #

Just like fromSharedPlusCBOR , except allows to transform the shared state with a lens.

toMemptyLens :: Monoid a => Lens' a b -> Lens' c b -> Lens' c a Source #

Using this function it is possible to compose two lenses. One will extract a value and another will used it for placing it into a empty monoid. Here is an example of how a second element of a tuple can be projected on the third element of a 3-tuple.

toMemptyLens _3 _2 == lens (\(_, b) -> (mempty, mempty, b)) (\(a, _) (_, _, b) -> (a, b))

Here is an example where we extract a second element of a tuple and insert it at third position of a three tuple while all other elements are set to mempty :

>>> import Lens.Micro
>>> ("foo","bar") ^. toMemptyLens _3 _2 :: (Maybe String, (), String)
(Nothing,(),"bar")

In the opposite direction of extracting the third element of a 3-tuple and replacing the second element of the tuple the setter is being applied to

>>> ("foo","bar") & toMemptyLens _3 _2 .~ (Just "baz", (), "booyah") :: (String, String)
("foo","booyah")

fromShareCBORfunctor :: ( FromCBOR (f b), Monad f) => Interns b -> Decoder s (f b) Source #

Share every item in a functor, have deserializing it