Skip to content

Commit

Permalink
Merge pull request #354 from input-output-hk/newhoggy/remove-constrai…
Browse files Browse the repository at this point in the history
…nts-from-constructors

Replace `IsCardanoEra` and `IsShelleyBasedEra` contraints in GADT constructors with `Typeable`
  • Loading branch information
newhoggy authored Nov 9, 2023
2 parents 6d91127 + c27daab commit 7c34db0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
12 changes: 3 additions & 9 deletions cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Cardano.Api.Eon.ShelleyBasedEra
ShelleyBasedEra(..)
, IsShelleyBasedEra(..)
, AnyShelleyBasedEra(..)
, anyShelleyBasedEra
, InAnyShelleyBasedEra(..)
, inAnyShelleyBasedEra
, shelleyBasedToCardanoEra
Expand Down Expand Up @@ -228,7 +227,8 @@ shelleyBasedEraConstraints = \case

data AnyShelleyBasedEra where
AnyShelleyBasedEra
:: ShelleyBasedEra era
:: Typeable era
=> ShelleyBasedEra era
-> AnyShelleyBasedEra

deriving instance Show AnyShelleyBasedEra
Expand Down Expand Up @@ -280,19 +280,13 @@ instance FromJSON AnyShelleyBasedEra where
"Conway" -> pure $ AnyShelleyBasedEra ShelleyBasedEraConway
wrong -> fail $ "Failed to parse unknown shelley-based era: " <> Text.unpack wrong

anyShelleyBasedEra :: ()
=> ShelleyBasedEra era
-> AnyShelleyBasedEra
anyShelleyBasedEra sbe =
AnyShelleyBasedEra sbe

-- | This pairs up some era-dependent type with a 'ShelleyBasedEra' value that
-- tells us what era it is, but hides the era type. This is useful when the era
-- is not statically known, for example when deserialising from a file.
--
data InAnyShelleyBasedEra thing where
InAnyShelleyBasedEra
:: IsShelleyBasedEra era
:: Typeable era
=> ShelleyBasedEra era
-> thing era
-> InAnyShelleyBasedEra thing
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/Eras/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ cardanoEraConstraints = \case

data AnyCardanoEra where
AnyCardanoEra
:: IsCardanoEra era
:: Typeable era
=> CardanoEra era
-> AnyCardanoEra

Expand Down Expand Up @@ -390,7 +390,7 @@ anyCardanoEra = \case
--
data InAnyCardanoEra thing where
InAnyCardanoEra
:: IsCardanoEra era
:: Typeable era
=> CardanoEra era
-> thing era
-> InAnyCardanoEra thing
Expand Down
1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ module Cardano.Api (
ShelleyBasedEra(..),
IsShelleyBasedEra(..),
AnyShelleyBasedEra(..),
anyShelleyBasedEra,
InAnyShelleyBasedEra(..),
inAnyShelleyBasedEra,
shelleyBasedToCardanoEra,
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ prop_toJSON_CardanoMatchesShelley :: Property
prop_toJSON_CardanoMatchesShelley = property $ do
AnyShelleyBasedEra sbe <- forAll $ Gen.element [minBound..maxBound]

toJSON (anyShelleyBasedEra sbe) === toJSON (anyCardanoEra (shelleyBasedToCardanoEra sbe))
toJSON (AnyShelleyBasedEra sbe) === toJSON (anyCardanoEra (shelleyBasedToCardanoEra sbe))

tests :: TestTree
tests = testGroup "Test.Cardano.Api.Json"
Expand Down

0 comments on commit 7c34db0

Please sign in to comment.