Skip to content

Commit

Permalink
Merge pull request #665 from IntersectMBO/mgalazyn/refactor/remove-so…
Browse files Browse the repository at this point in the history
…me-instances

Remove `Show (Some a)` and `Eq (Some a)`. Add `Show (Some Era)` and `Eq (Some Era)`.
  • Loading branch information
carbolymer authored Nov 19, 2024
2 parents 7df31dc + b72fc8d commit fba6b41
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cardano-api/internal/Cardano/Api/Experimental/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type family LedgerEra era = (r :: Type) | r -> era where
LedgerEra BabbageEra = Ledger.Babbage
LedgerEra ConwayEra = Ledger.Conway

-- | An existential type for singleton types. Use to hold any era e.g. @Some Era@. One can then bring the
-- era witness back into scope for example using this pattern:
-- | An existential wrapper for types of kind @k -> Types@. Use it to hold any era e.g. @Some Era@. One can
-- then bring the era witness back into scope for example using this pattern:
-- @
-- anyEra = Some ConwayEra
-- -- then later in the code
Expand All @@ -81,15 +81,6 @@ data Some (f :: k -> Type) where
=> f a
-> Some f

-- | Assumes that @f@ is a singleton
instance Show (Some f) where
showsPrec _ (Some v) = showsTypeRep (typeOf v)

-- | Assumes that @f@ is a singleton
instance TestEquality f => Eq (Some f) where
Some era1 == Some era2 =
isJust $ testEquality era1 era2

-- | Represents the eras in Cardano's blockchain.
-- This type represents eras currently on mainnet and new eras which are
-- in development.
Expand Down Expand Up @@ -119,6 +110,12 @@ instance TestEquality Era where
instance ToJSON (Era era) where
toJSON = eraToStringLike

instance Show (Some Era) where
showsPrec _ (Some era) = shows era

instance Eq (Some Era) where
Some era1 == Some era2 = isJust $ testEquality era1 era2

instance Bounded (Some Era) where
minBound = Some BabbageEra
maxBound = Some ConwayEra
Expand Down

0 comments on commit fba6b41

Please sign in to comment.