Skip to content

Commit

Permalink
Be more explicit about kinds.
Browse files Browse the repository at this point in the history
The aim here is to reduce the likelihood of failures due to kind
mismatch in the future, as well as to help with documentation.
  • Loading branch information
nc6 committed Oct 28, 2020
1 parent e03d7bb commit 8c848fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion shelley-ma/impl/src/Cardano/Ledger/ShelleyMA.hs
@@ -1,6 +1,8 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wimplicit-kind-vars #-}

module Cardano.Ledger.ShelleyMA where

Expand All @@ -24,13 +26,14 @@ data MaryOrAllegra = Mary | Allegra
data ShelleyMAEra (ma :: MaryOrAllegra) c

instance
forall c (ma :: MaryOrAllegra).
(Typeable ma, Cardano.Ledger.Crypto.Crypto c) =>
Era (ShelleyMAEra ma c)
where
type Crypto (ShelleyMAEra ma c) = c

type family MAValue (x :: MaryOrAllegra) era :: Type where
MAValue 'Allegra era = Coin
MAValue 'Allegra _ = Coin
MAValue 'Mary era = Value era

type instance Core.Value (ShelleyMAEra m c) = MAValue m (ShelleyMAEra m c)
5 changes: 3 additions & 2 deletions shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/Rules/Utxo.hs
Expand Up @@ -255,9 +255,10 @@ utxoTransition = do
--------------------------------------------------------------------------------

instance
forall c (ma :: MaryOrAllegra).
( CryptoClass.Crypto c,
Typeable ma,
ShelleyBased (ShelleyMAEra (ma :: MaryOrAllegra) c),
ShelleyBased (ShelleyMAEra ma c),
Core.TxBody (ShelleyMAEra ma c) ~ TxBody (ShelleyMAEra ma c)
) =>
STS (UTXO (ShelleyMAEra ma c))
Expand All @@ -277,7 +278,7 @@ instance

instance
(CryptoClass.Crypto c, Typeable ma) =>
Embed (PPUP (ShelleyMAEra ma c)) (UTXO (ShelleyMAEra ma c))
Embed (PPUP (ShelleyMAEra (ma :: MaryOrAllegra) c)) (UTXO (ShelleyMAEra ma c))
where
wrapFailed = UpdateFailure

Expand Down
4 changes: 3 additions & 1 deletion shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/Rules/Utxow.hs
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
Expand All @@ -15,7 +16,7 @@ import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as CryptoClass
import Cardano.Ledger.Mary.Value (PolicyID, Value, policies, policyID)
import Cardano.Ledger.Shelley (ShelleyBased)
import Cardano.Ledger.ShelleyMA (ShelleyMAEra)
import Cardano.Ledger.ShelleyMA (MaryOrAllegra, ShelleyMAEra)
import Cardano.Ledger.ShelleyMA.Scripts ()
import Cardano.Ledger.ShelleyMA.TxBody ()
import Cardano.Ledger.Val (Val)
Expand Down Expand Up @@ -113,6 +114,7 @@ scriptsNeeded u tx =
--------------------------------------------------------------------------------

instance
forall c (ma :: MaryOrAllegra).
( CryptoClass.Crypto c,
Typeable ma,
STS (UTXO (ShelleyMAEra ma c)),
Expand Down

0 comments on commit 8c848fb

Please sign in to comment.