-
Notifications
You must be signed in to change notification settings - Fork 22
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
Rename FeatureInEra
to Eon
#247
Conversation
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to | ||
-- particular eras such that it isn't possible construct code that uses functionality | ||
-- that is not available given eras. | ||
class IsEon (eon :: Type -> Type) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever name. 🙂 I guess we can rename era ranges into e.g. AlonzoOnwardsEon
to highlight that those are eons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of dropping the suffix altogether so that it is just AlonzoOnwards
but I would do it as a separate change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a more appropriate name but instead of IsEon
why not InEon
and inEon
?
The comment could read: Determine the value to use in a span of eras (eon)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eon
is unclaimed so it can be just that.
The instances would look like this:
instance Eon AlonzoOnwards where
...
@@ -1029,8 +1029,8 @@ data ProtocolUTxOCostPerWordFeature era where | |||
deriving instance Eq (ProtocolUTxOCostPerWordFeature era) | |||
deriving instance Show (ProtocolUTxOCostPerWordFeature era) | |||
|
|||
instance FeatureInEra ProtocolUTxOCostPerWordFeature where | |||
featureInEra no yes = \case | |||
instance IsEon ProtocolUTxOCostPerWordFeature where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the naming point of view, I think this is confusing. Feature isn't an eon. If we want to use the same class for that, I'd suggest using more universal name e.g. IsAvailableInEra
or IsPresentInEra
or HasWitnessInEra
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProtocolUTxOCostPerWordFeature
could actually be replaced with AlonzoEraOnly
because they are isomorphic to each other:
data ProtocolUTxOCostPerWordFeature era where
ProtocolUpdateUTxOCostPerWordInAlonzoEra :: ProtocolUTxOCostPerWordFeature AlonzoEra
vs
data AlonzoEraOnly era where
AlonzoEraOnlyAlonzo :: AlonzoEraOnly AlonzoEra
and the latter has good integration with era feature switching functions and constraints summoning whereas the former is just the datatype.
All the feature GADTs can actually be replaced in this manner so the overloaded use of the name should not arise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. If we won't have to use this class for features I'm all for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice name, but I don't think it fits our case in 100% https://github.com/input-output-hk/cardano-api/pull/247/files#r1328491918
@Jimbo4350 what do you think?
cba294a
to
3264c3a
Compare
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to | ||
-- particular eras such that it isn't possible construct code that uses functionality | ||
-- that is not available given eras. | ||
class IsEon (eon :: Type -> Type) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a more appropriate name but instead of IsEon
why not InEon
and inEon
?
The comment could read: Determine the value to use in a span of eras (eon)
a44dc7e
to
a563862
Compare
ce64aad
to
412242a
Compare
9853461
to
822425f
Compare
import Cardano.Api.Eras.Core | ||
|
||
-- | A value only if the eon includes era | ||
data Featured eon era a where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentEra
or targetEra
instead of era
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same sort of era
as as the era
in ShelleyBasedEra era
in that we don't say ShelleyBasedEra currentEra
. The qualification seems unnecessary.
-- but not others. | ||
class FeatureInEra (feature :: Type -> Type) where | ||
-- | Determine the value to use for a feature in a given 'CardanoEra'. | ||
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
-- | Determine the value to use for a feature in a given 'ShelleyBasedEra'. | ||
featureInShelleyBasedEra :: () | ||
=> FeatureInEra feature | ||
inEonEra :: () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inEonForEra
? inEonEra
is shorter but it's confusing to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted inEonForEra
and also forEraInEon
for the other function where CardanoEra era
is the first argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think current naming is confusing, but If you prefer the current state, feel free to merge as it is now.
inEraEonMaybe :: () | ||
=> Eon eon | ||
=> CardanoEra era -- ^ Era to check | ||
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era | ||
-> Maybe a -- ^ The value to use | ||
inEraEonMaybe era yes = | ||
eraInEon era Nothing (Just . yes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inEraEonMaybe :: () | |
=> Eon eon | |
=> CardanoEra era -- ^ Era to check | |
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era | |
-> Maybe a -- ^ The value to use | |
inEraEonMaybe era yes = | |
eraInEon era Nothing (Just . yes) | |
whenEraInEon :: () | |
=> Eon eon | |
=> CardanoEra era -- ^ Era to check | |
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era | |
-> Maybe a -- ^ The value to use | |
whenEraInEon era yes = | |
eraInEon era Nothing (Just . yes) |
also Alternative f
could be used instead of Maybe
everywhere
maybeEonInEra :: () | ||
=> Eon eon | ||
=> CardanoEra era -- ^ Era to check | ||
-> Maybe (eon era) -- ^ The eon if supported in the era | ||
maybeEonInEra = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybeEonInEra :: () | |
=> Eon eon | |
=> CardanoEra era -- ^ Era to check | |
-> Maybe (eon era) -- ^ The eon if supported in the era | |
maybeEonInEra = | |
eonHasEraMaybe :: () | |
=> Eon eon | |
=> CardanoEra era -- ^ Era to check | |
-> Maybe (eon era) -- ^ The eon if supported in the era | |
eonHasEraMaybe = |
|
||
maybeFeatureInShelleyBasedEra :: () | ||
=> FeatureInEra feature | ||
maybeEonInShelleyBasedEra :: () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybeEonInShelleyBasedEra :: () | |
whenShelleyBasedEraInEon :: () |
|
||
inShelleyBasedEraFeature :: () | ||
=> FeatureInEra feature | ||
inShelleyBasedEraEon :: () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inShelleyBasedEraEon :: () | |
shelleyBasedEraInEon :: () |
inEonEra Nothing Just | ||
|
||
-- | Determine the value to use for a eon in a given 'ShelleyBasedEra'. | ||
eonInShelleyBasedEra :: () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is just inShelleyBasedEraEon
with its arguments reordered. I think it is redundant and inShelleyBasedEraEon
can be used everywhere instead.
|
||
inShelleyBasedEraFeatureMaybe :: () | ||
=> FeatureInEra feature | ||
inShelleyBasedEraEonMaybe :: () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inShelleyBasedEraEonMaybe :: () | |
whenShelleyBasedEraInEon :: () |
-- | Determine the value to use for a feature in a given 'ShelleyBasedEra'. | ||
featureInShelleyBasedEra :: () | ||
=> FeatureInEra feature | ||
inEonEra :: () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inEonEra :: () | |
hasEra :: () |
or hasEonEra
or eraInEon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted this suggestion: #247 (comment)
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to | ||
-- particular eras such that it isn't possible construct code that uses functionality | ||
-- that is not available given eras. | ||
class Eon (eon :: Type -> Type) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class Eon (eon :: Type -> Type) where | |
class IsEon (eon :: Type -> Type) where |
I feel that using IsEon
instead of plain noun would be better suited here and represent the fact that something is an eon. I'd reserve plain nouns for concrete datatypes, just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with IsEon
or Eon
. I don't think there is a strong case for either. The standard library actually uses both.
For example the standard library uses Generic
instead of IsGeneric
whilst it uses IsString
instead of String
. I think the Is
in IsString
is necessary because the type String
already exists, but we don't use IsGeneric
and use Generic
instead because there isn't a Generic
type so the name is available for the type class.
822425f
to
da43ac2
Compare
da43ac2
to
9469db1
Compare
I don't actually prefer the current wording. I think the current wording is sub-optimal. Nevertheless the goal of the PR isn't to optimise the naming of these functions. It's to remove the word "feature" because it isn't appropriate for the abstraction. I'm merging this PR as it is to unblock other work. We can have a separate PR to sort out the naming. |
…ay-1.8 Update cardano-cli to newer cardano-ledger
Changelog
Context
The types that we have so far called "features" do not seem like features at all. Rather they represent some set of eras that scope the applicability of certain functionality.
This PR renames them to be "eons" instead. An
Eon
is some subset of eras.Checklist
See Running tests for more details
.cabal
files are updatedhlint
. See.github/workflows/check-hlint.yml
to get thehlint
versionstylish-haskell
. See.github/workflows/stylish-haskell.yml
to get thestylish-haskell
versionghc-8.10.7
andghc-9.2.7