Skip to content

Commit

Permalink
Cleanup: Remove type class Dom
Browse files Browse the repository at this point in the history
* it was only instantiated for `UTxO`
* after recent commits, it is only occurring in testing code
  • Loading branch information
HeinrichApfelmus committed Feb 25, 2022
1 parent fb89813 commit caf3ac8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
12 changes: 3 additions & 9 deletions docs/user-guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,15 @@ Wallet Backend specifications, the notation is inspired from the [Z notation](ht
<details>
<summary>What is <code>dom</code> from <strong>Lemma 2.1</strong></summary>

There are multiple occurrences in the spec of expressions like: `(dom u ∩ ins) ◃ u`. The meaning of `dom u` isn't quite clearly defined anywhere but refers to the set of keys from the mapping defined by `u: txin ↦ txout`. Hence,
`dom u` refers to all `txin` available in `u`.
There are multiple occurrences in the spec of expressions like: `(dom u ∩ ins) ◃ u`. The meaning of `dom u` isn't quite clearly defined anywhere but refers to the set of keys from the mapping defined by `u: txin ↦ txout`. Hence, `dom u` refers to all `txin` available in `u`.

In Haskell, this translates to:

```hs
class Dom a where
type DomElem a :: *
dom :: a -> Set (DomElem a)

newtype UTxO = UTxO (Map TxIn TxOut)

instance Dom UTxO where
type DomElem UTxO = TxIn
dom (UTxO utxo) = Set.fromList $ Map.keys utxo
dom :: UTxO -> Set TxIn
dom (UTxO utxo) = Set.fromList $ Map.keys utxo
```
</details>

Expand Down
19 changes: 5 additions & 14 deletions lib/core/src/Cardano/Wallet/Primitive/Types/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module Cardano.Wallet.Primitive.Types.UTxO
(
-- * UTxO
UTxO (..)
, Dom (..)

, dom
, null
, size
, balance
Expand Down Expand Up @@ -73,8 +73,6 @@ import Data.Functor.Identity
( runIdentity )
import Data.Generics.Internal.VL.Lens
( view )
import Data.Kind
( Type )
import Data.List.NonEmpty
( NonEmpty (..) )
import Data.Map.Strict
Expand Down Expand Up @@ -106,17 +104,6 @@ newtype UTxO = UTxO { unUTxO :: Map TxIn TxOut }

instance NFData UTxO

-- | Allows us to define the "domain" of any type — @UTxO@ in particular — and
-- use 'dom' to refer to the /inputs/ of an /utxo/.
--
class Dom a where
type DomElem a :: Type
dom :: a -> Set (DomElem a)

instance Dom UTxO where
type DomElem UTxO = TxIn
dom (UTxO utxo) = Map.keysSet utxo

instance Buildable UTxO where
build (UTxO utxo) =
blockListF' "-" utxoF (Map.toList utxo)
Expand All @@ -129,6 +116,10 @@ instance Buildable UTxO where
]
buildMap = blockMapF . fmap (first $ id @String)

-- | Domain of a 'UTxO' = the set of /inputs/ of the /utxo/.
dom :: UTxO -> Set TxIn
dom (UTxO utxo) = Map.keysSet utxo

-- | Compute the balance of a UTxO
balance :: UTxO -> TokenBundle
balance =
Expand Down
2 changes: 1 addition & 1 deletion lib/core/test/unit/Cardano/Wallet/Primitive/ModelSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import Cardano.Wallet.Primitive.Types.Tx
import Cardano.Wallet.Primitive.Types.Tx.Gen
( genTx, genTxIn, genTxOut, shrinkTx, shrinkTxIn, shrinkTxOut )
import Cardano.Wallet.Primitive.Types.UTxO
( Dom (..), UTxO (..), balance, excluding, filterByAddress, restrictedTo )
( UTxO (..), balance, dom, excluding, filterByAddress, restrictedTo )
import Cardano.Wallet.Primitive.Types.UTxO.Gen
( genUTxO, shrinkUTxO )
import Cardano.Wallet.Util
Expand Down
2 changes: 1 addition & 1 deletion lib/core/test/unit/Cardano/Wallet/Primitive/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ import Cardano.Wallet.Primitive.Types.Tx.Gen
( genTx, shrinkTx )
import Cardano.Wallet.Primitive.Types.UTxO
( BoundType
, Dom (..)
, HistogramBar (..)
, UTxO (..)
, UTxOStatistics (..)
, balance
, computeUtxoStatistics
, dom
, excluding
, isSubsetOf
, log10
Expand Down

0 comments on commit caf3ac8

Please sign in to comment.