-
Notifications
You must be signed in to change notification settings - Fork 167
Remove listLenBound from EncCBORGroup class #5383
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||
| {-# LANGUAGE FlexibleInstances #-} | ||||||
| {-# LANGUAGE OverloadedStrings #-} | ||||||
| {-# LANGUAGE RankNTypes #-} | ||||||
| {-# LANGUAGE ScopedTypeVariables #-} | ||||||
| {-# LANGUAGE TypeApplications #-} | ||||||
|
|
||||||
| module Cardano.Ledger.Binary.Group ( | ||||||
| CBORGroup (..), | ||||||
|
|
@@ -12,8 +14,7 @@ module Cardano.Ledger.Binary.Group ( | |||||
|
|
||||||
| import Cardano.Ledger.Binary.Decoding | ||||||
| import Cardano.Ledger.Binary.Encoding | ||||||
| import Data.Proxy | ||||||
| import Data.Typeable | ||||||
| import Data.Typeable (Proxy (..), Typeable) | ||||||
|
|
||||||
| -------------------------------------------------------------------------------- | ||||||
| -- CBORGroup | ||||||
|
|
@@ -26,10 +27,11 @@ instance (DecCBORGroup a, EncCBORGroup a) => DecCBOR (CBORGroup a) where | |||||
| decCBOR = CBORGroup <$> groupRecord | ||||||
|
|
||||||
| instance EncCBORGroup a => EncCBOR (CBORGroup a) where | ||||||
| encCBOR (CBORGroup x) = encodeListLen (listLen x) <> encCBORGroup x | ||||||
| encCBOR (CBORGroup x) = encodeListLen (listLen $ Proxy @a) <> encCBORGroup x | ||||||
|
|
||||||
| groupRecord :: forall a s. (EncCBORGroup a, DecCBORGroup a) => Decoder s a | ||||||
| groupRecord = decodeRecordNamed "CBORGroup" (fromIntegral . toInteger . listLen) decCBORGroup | ||||||
| groupRecord = | ||||||
| decodeRecordNamed "CBORGroup" (fromIntegral . toInteger . const (listLen $ Proxy @a)) decCBORGroup | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like I missed one more suggestion. Using
Suggested change
|
||||||
|
|
||||||
| -------------------------------------------------------------------------------- | ||||||
| -- EncCBORGroup | ||||||
|
|
@@ -38,13 +40,10 @@ groupRecord = decodeRecordNamed "CBORGroup" (fromIntegral . toInteger . listLen) | |||||
| class EncCBORGroup a where | ||||||
| encCBORGroup :: a -> Encoding | ||||||
|
|
||||||
| listLen :: a -> Word | ||||||
| listLen :: Proxy a -> Word | ||||||
|
|
||||||
| -- | an upper bound for 'listLen', used in 'Size' expressions. | ||||||
| listLenBound :: Proxy a -> Word | ||||||
|
|
||||||
| listLenInt :: EncCBORGroup a => a -> Int | ||||||
| listLenInt x = fromIntegral (listLen x) | ||||||
| listLenInt :: forall a. EncCBORGroup a => a -> Int | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not a Proxy here too, instead of a value
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point - though I find that not having to pass the proxy is half of the convenience of this function: it then becomes
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with both of you. That's why I think the best approach here will be to make it:
Suggested change
This will allow using it with concrete types instead of just Plain.decodeRecordNamed "OCert" (listLenInt . Just) decodeOCertFieldsor Plain.decodeRecordNamed "OCert" (listLenInt . Identity) decodeOCertFieldsThis will keep it consistent, while still allow for convenience to use the value for inferring the type. |
||||||
| listLenInt _ = fromIntegral $ listLen $ Proxy @a | ||||||
|
|
||||||
| -------------------------------------------------------------------------------- | ||||||
| -- DecCBORGroup | ||||||
|
|
@@ -57,7 +56,6 @@ instance EncCBOR a => EncCBORGroup (a, a) where | |||||
| encCBORGroup (x, y) = | ||||||
| encCBOR x <> encCBOR y | ||||||
| listLen _ = 2 | ||||||
| listLenBound _ = 2 | ||||||
|
|
||||||
| instance DecCBOR a => DecCBORGroup (a, a) where | ||||||
| decCBORGroup = do | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ module Cardano.Ledger.Core ( | |
| binaryUpgradeTxAuxData, | ||
| fromStrictMaybeL, | ||
| toStrictMaybeL, | ||
| toProxy, | ||
|
|
||
| -- * Era | ||
| module Cardano.Ledger.Core.Era, | ||
|
|
@@ -683,3 +684,6 @@ fromStrictMaybeL = lens strictMaybeToMaybe (const maybeToStrictMaybe) | |
|
|
||
| instance EraTx era => HasOKey TxId (Tx l era) where | ||
| toOKey = txIdTx | ||
|
|
||
| toProxy :: forall a. a -> Proxy a | ||
| toProxy _ = Proxy | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lehins
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I totally agree with the fact that this is a better function for us than
The irony about this function, is that I have defined a function just like that in the past In order to stay consistent with the name in base, I think it would be better to call this one With all this in mind, I think it would be a prefect time for you to make this small contribution in a place other than ledger. So, please:
FTR. We don't normally go through all these troubles just to get one function form some place. I am only suggesting you do this to get familiar with the process of making release to CHaP and pulling in newer dependencies in |
||
Uh oh!
There was an error while loading. Please reload this page.