{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Ouroboros.Consensus.Ledger.Tables.Basics (
LedgerStateKind
, MapKind
, LedgerTables (..)
, MemPackIdx
, SameUtxoTypes
, TxIn
, TxOut
, castLedgerTables
) where
import Data.Coerce (coerce)
import Data.Kind (Type)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import Ouroboros.Consensus.Ticked (Ticked)
type MapKind = Type -> Type -> Type
type LedgerStateKind = MapKind -> Type
type LedgerTables :: LedgerStateKind -> MapKind -> Type
newtype LedgerTables l mk = LedgerTables {
forall (l :: LedgerStateKind) (mk :: MapKind).
LedgerTables l mk -> mk (TxIn l) (TxOut l)
getLedgerTables :: mk (TxIn l) (TxOut l)
}
deriving stock (forall x. LedgerTables l mk -> Rep (LedgerTables l mk) x)
-> (forall x. Rep (LedgerTables l mk) x -> LedgerTables l mk)
-> Generic (LedgerTables l mk)
forall x. Rep (LedgerTables l mk) x -> LedgerTables l mk
forall x. LedgerTables l mk -> Rep (LedgerTables l mk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (l :: LedgerStateKind) (mk :: MapKind) x.
Rep (LedgerTables l mk) x -> LedgerTables l mk
forall (l :: LedgerStateKind) (mk :: MapKind) x.
LedgerTables l mk -> Rep (LedgerTables l mk) x
$cfrom :: forall (l :: LedgerStateKind) (mk :: MapKind) x.
LedgerTables l mk -> Rep (LedgerTables l mk) x
from :: forall x. LedgerTables l mk -> Rep (LedgerTables l mk) x
$cto :: forall (l :: LedgerStateKind) (mk :: MapKind) x.
Rep (LedgerTables l mk) x -> LedgerTables l mk
to :: forall x. Rep (LedgerTables l mk) x -> LedgerTables l mk
Generic
deriving stock instance Show (mk (TxIn l) (TxOut l))
=> Show (LedgerTables l mk)
deriving stock instance Eq (mk (TxIn l) (TxOut l))
=> Eq (LedgerTables l mk)
deriving newtype instance NoThunks (mk (TxIn l) (TxOut l))
=> NoThunks (LedgerTables l mk)
type TxIn :: LedgerStateKind -> Type
type family TxIn l
type TxOut :: LedgerStateKind -> Type
type family TxOut l
type instance TxIn (LedgerTables l) = TxIn l
type instance TxOut (LedgerTables l) = TxOut l
type instance TxIn (Ticked l) = TxIn l
type instance TxOut (Ticked l) = TxOut l
type MemPackIdx :: LedgerStateKind -> MapKind -> Type
type family MemPackIdx l mk where
MemPackIdx (LedgerTables l) mk = MemPackIdx l mk
MemPackIdx (Ticked l) mk = MemPackIdx l mk
MemPackIdx l mk = l mk
type SameUtxoTypes l l' = (TxIn l ~ TxIn l', TxOut l ~ TxOut l')
castLedgerTables ::
SameUtxoTypes l l'
=> LedgerTables l mk
-> LedgerTables l' mk
castLedgerTables :: forall (l :: LedgerStateKind) (l' :: LedgerStateKind)
(mk :: MapKind).
SameUtxoTypes l l' =>
LedgerTables l mk -> LedgerTables l' mk
castLedgerTables = LedgerTables l mk -> LedgerTables l' mk
forall a b. Coercible a b => a -> b
coerce