Skip to content

Commit dd37ea8

Browse files
authored
Make Enum PlutusTx.Rational plc compilable (#7474)
1 parent fe0786e commit dd37ea8

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fixed the `Enum PlutusTx.Rational` to be compilable with plc compiler

plutus-tx/src/PlutusTx/Ratio.hs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import GHC.Generics
6363
import PlutusTx.Blueprint.Class (HasBlueprintSchema (..))
6464
import PlutusTx.Blueprint.Definition (HasBlueprintDefinition (..), HasSchemaDefinition)
6565
import Prettyprinter (Pretty (..), (<+>))
66-
import Prelude (Ord (..), Show, (*))
6766
import Prelude qualified as Haskell
6867

6968
{-| Represents an arbitrary-precision ratio.
@@ -73,7 +72,7 @@ The following two invariants are maintained:
7372
1. The denominator is greater than zero.
7473
2. The numerator and denominator are coprime. -}
7574
data Rational = Rational Integer Integer
76-
deriving stock (Haskell.Eq, Show, Generic)
75+
deriving stock (Haskell.Eq, Haskell.Show, Generic)
7776

7877
makeLift ''Rational
7978

@@ -96,12 +95,12 @@ instance P.Ord Rational where
9695
{-# INLINEABLE (>) #-}
9796
Rational n d > Rational n' d' = (n P.* d') P.> (n' P.* d)
9897

99-
instance Ord Rational where
100-
compare (Rational n d) (Rational n' d') = compare (n * d') (n' * d)
101-
Rational n d <= Rational n' d' = (n * d') <= (n' * d)
102-
Rational n d >= Rational n' d' = (n * d') >= (n' * d)
103-
Rational n d < Rational n' d' = (n * d') < (n' * d)
104-
Rational n d > Rational n' d' = (n * d') > (n' * d)
98+
instance Haskell.Ord Rational where
99+
compare (Rational n d) (Rational n' d') = Haskell.compare (n Haskell.* d') (n' Haskell.* d)
100+
Rational n d <= Rational n' d' = (n Haskell.* d') Haskell.<= (n' Haskell.* d)
101+
Rational n d >= Rational n' d' = (n Haskell.* d') Haskell.>= (n' Haskell.* d)
102+
Rational n d < Rational n' d' = (n Haskell.* d') Haskell.< (n' Haskell.* d)
103+
Rational n d > Rational n' d' = (n Haskell.* d') Haskell.> (n' Haskell.* d)
105104

106105
instance P.AdditiveSemigroup Rational where
107106
{-# INLINEABLE (+) #-}
@@ -367,11 +366,11 @@ instance Enum Rational where
367366
{-# INLINEABLE enumFromTo #-}
368367
enumFromTo x lim
369368
-- See why adding half is needed in the Haskell report: https://www.haskell.org/onlinereport/haskell2010/haskellch6.html
370-
| x > lim P.+ Rational 1 2 = []
369+
| x P.> lim P.+ Rational 1 2 = []
371370
| P.True = x : enumFromTo (succ x) lim
372371
{-# INLINEABLE enumFromThenTo #-}
373372
enumFromThenTo x y lim =
374-
if delta >= P.zero
373+
if delta P.>= P.zero
375374
then up_list x
376375
else dn_list x
377376
where
@@ -380,12 +379,12 @@ instance Enum Rational where
380379
mid = numerator delta `unsafeRatio` (denominator delta P.* 2)
381380
up_list x1 =
382381
-- See why adding mid is needed in the Haskell report: https://www.haskell.org/onlinereport/haskell2010/haskellch6.html
383-
if x1 > lim P.+ mid
382+
if x1 P.> lim P.+ mid
384383
then []
385384
else x1 : up_list (x1 P.+ delta)
386385
dn_list x1 =
387386
-- See why adding mid is needed in the Haskell report: https://www.haskell.org/onlinereport/haskell2010/haskellch6.html
388-
if x1 < lim P.+ mid
387+
if x1 P.< lim P.+ mid
389388
then []
390389
else x1 : dn_list (x1 P.+ delta)
391390

0 commit comments

Comments
 (0)