Skip to content

Commit 3c34b71

Browse files
committed
Add onPerasRoundNo helper and Num instance
1 parent 5da78b6 commit 3c34b71

File tree

1 file changed

+9
-1
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block

1 file changed

+9
-1
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block/SupportsPeras.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
module Ouroboros.Consensus.Block.SupportsPeras
1515
( PerasRoundNo (..)
16+
, onPerasRoundNo
1617
, PerasWeight (..)
1718
, BlockSupportsPeras (..)
1819
, PerasCert (..)
@@ -31,6 +32,7 @@ module Ouroboros.Consensus.Block.SupportsPeras
3132
import Codec.Serialise (Serialise (..))
3233
import Codec.Serialise.Decoding (decodeListLenOf)
3334
import Codec.Serialise.Encoding (encodeListLen)
35+
import Data.Coerce (coerce)
3436
import Data.Monoid (Sum (..))
3537
import Data.Proxy (Proxy (..))
3638
import Data.Word (Word64)
@@ -45,14 +47,20 @@ import Quiet (Quiet (..))
4547
newtype PerasRoundNo = PerasRoundNo {unPerasRoundNo :: Word64}
4648
deriving Show via Quiet PerasRoundNo
4749
deriving stock Generic
48-
deriving newtype (Enum, Eq, Ord, NoThunks, Serialise)
50+
deriving newtype (Enum, Eq, Ord, Num, Bounded, NoThunks, Serialise)
4951

5052
instance Condense PerasRoundNo where
5153
condense = show . unPerasRoundNo
5254

5355
instance ShowProxy PerasRoundNo where
5456
showProxy _ = "PerasRoundNo"
5557

58+
-- | Lift a binary operation on 'Word64' to 'PerasRoundNo'
59+
onPerasRoundNo ::
60+
(Word64 -> Word64 -> Word64) ->
61+
(PerasRoundNo -> PerasRoundNo -> PerasRoundNo)
62+
onPerasRoundNo = coerce
63+
5664
newtype PerasWeight = PerasWeight {unPerasWeight :: Word64}
5765
deriving Show via Quiet PerasWeight
5866
deriving stock Generic

0 commit comments

Comments
 (0)