Skip to content

Commit ff77e30

Browse files
committed
WIP
1 parent f8c7ed9 commit ff77e30

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Ledger/Tables/Combinators.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# LANGUAGE TypeApplications #-}
13
{-# LANGUAGE ConstraintKinds #-}
24
{-# LANGUAGE DeriveTraversable #-}
35
{-# LANGUAGE DerivingStrategies #-}
@@ -83,6 +85,8 @@ import Ouroboros.Consensus.Ledger.Tables.Basics
8385
import Ouroboros.Consensus.Ledger.Tables.MapKind
8486
import Ouroboros.Consensus.Util ((...:), (..:), (.:))
8587
import Ouroboros.Consensus.Util.IndexedMemPack
88+
import Data.Proxy
89+
import Lens.Micro
8690

8791
{-------------------------------------------------------------------------------
8892
Common constraints
@@ -112,11 +116,12 @@ type LedgerTableConstraints' l k v =
112116

113117
-- | Like 'bmap', but for ledger tables.
114118
ltmap ::
115-
LedgerTableConstraints l =>
119+
forall l (tag :: TAG) mk1 mk2. LedgerTableConstraints l =>
120+
Proxy tag ->
116121
(forall k v. LedgerTableConstraints' l k v => mk1 k v -> mk2 k v) ->
117122
LedgerTables l mk1 ->
118123
LedgerTables l mk2
119-
ltmap f (LedgerTables x) = LedgerTables $ f x
124+
ltmap p f tbs = tbs & onTable (Proxy @l) p %~ Table . f . getTable
120125

121126
{-------------------------------------------------------------------------------
122127
Traversable

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Ledger/Tables/MapKind.hs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Ouroboros.Consensus.Ledger.Tables.MapKind
1818
, NoThunksMK
1919
, ShowMK
2020
, ZeroableMK (..)
21-
, bimapLedgerTables
21+
-- , bimapLedgerTables
2222

2323
-- * Concrete MapKinds
2424
, CodecMK (..)
@@ -35,6 +35,8 @@ import qualified Codec.CBOR.Encoding as CBOR
3535
import Data.Kind (Constraint)
3636
import Data.Map.Strict (Map)
3737
import qualified Data.Map.Strict as Map
38+
import Data.Proxy
39+
import Data.SOP.Strict
3840
import Data.Set (Set)
3941
import qualified Data.Set as Set
4042
import GHC.Generics (Generic)
@@ -78,26 +80,35 @@ class
7880
(forall k v. (NoThunks k, NoThunks v) => NoThunks (mk k v)) =>
7981
NoThunksMK mk
8082

81-
-- | Map both keys and values in ledger tables.
82-
--
83-
-- For keys, it has the same caveats as 'Data.Map.Strict.mapKeys' or
84-
-- `Data.Set.map', namely that only injective functions are suitable to be used
85-
-- here.
86-
bimapLedgerTables ::
87-
forall x y mk.
88-
( CanMapKeysMK mk
89-
, CanMapMK mk
90-
, Ord (TxIn y)
91-
) =>
92-
(TxIn x -> TxIn y) ->
93-
(TxOut x -> TxOut y) ->
94-
LedgerTables x mk ->
95-
LedgerTables y mk
96-
bimapLedgerTables f g =
97-
LedgerTables
98-
. mapKeysMK f
99-
. mapMK g
100-
. getLedgerTables
83+
-- -- | Map both keys and values in ledger tables.
84+
-- --
85+
-- -- For keys, it has the same caveats as 'Data.Map.Strict.mapKeys' or
86+
-- -- `Data.Set.map', namely that only injective functions are suitable to be used
87+
-- -- here.
88+
-- bimapLedgerTables ::
89+
-- forall tag x y mk.
90+
-- ( CanMapKeysMK mk
91+
-- , CanMapMK mk
92+
-- , Ord (TxIn y)
93+
-- ) =>
94+
-- (TxIn x -> TxIn y) ->
95+
-- (TxOut x -> TxOut y) ->
96+
-- (Credential x -> Credential y) ->
97+
-- (AccountState x -> AccountState y) ->
98+
-- LedgerTables x mk ->
99+
-- LedgerTables y mk
100+
-- bimapLedgerTables f g h i t =
101+
102+
-- `onUTxOTable` ( Table
103+
-- . mapKeysMK f
104+
-- . mapMK g
105+
-- . getTable
106+
-- )
107+
-- `onAccountsTable` ( Table
108+
-- . mapKeysMK f
109+
-- . mapMK g
110+
-- . getTable
111+
-- )
101112

102113
{-------------------------------------------------------------------------------
103114
EmptyMK

0 commit comments

Comments
 (0)