Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace IsCardanoEra and IsShelleyBasedEra contraints in GADT constructors with Typeable #354

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -105,7 +105,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