Skip to content

Commit dc7bf5e

Browse files
committed
Address come comments
1 parent 3ca2a2e commit dc7bf5e

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

plutus-tx/src/PlutusTx/Eq/Class.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ module PlutusTx.Eq.Class
66
import PlutusTx.Bool
77
import PlutusTx.Builtins qualified as Builtins
88

9-
{- HLINT ignore -}
10-
119
infix 4 ==
1210

13-
-- Copied from the GHC definition
11+
{- | The 'Eq' class defines equality ('==').
1412
15-
-- | The 'Eq' class defines equality ('==').
13+
(/=) deliberately omitted, to make this a one-method class which has a
14+
simpler representation
15+
-}
1616
class Eq a where
1717
(==) :: a -> a -> Bool
1818

19-
-- (/=) deliberately omitted, to make this a one-method class which has a
20-
-- simpler representation
21-
2219
infix 4 /=
2320
(/=) :: (Eq a) => a -> a -> Bool
2421
x /= y = not (x == y)

plutus-tx/src/PlutusTx/Eq/TH.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import Language.Haskell.TH as TH
1010
import Language.Haskell.TH.Datatype as TH
1111
import Data.Deriving.Internal (varTToName)
1212

13+
{- | derive a PlutusTx.Eq instance for a datatype/newtype, similar to Haskell's `deriving stock Eq`.
14+
15+
One shortcoming compared to Haskell's deriving is that you cannot `PlutusTx.deriveEq` for polymorphic phantom types.
16+
-}
1317
deriveEq :: TH.Name -> TH.Q [TH.Dec]
1418
deriveEq name = do
1519
TH.DatatypeInfo

plutus-tx/test/Eq/Spec.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ data SomeLargeADT a b c d e =
2323
deriving stock HS.Eq
2424
deriveEq ''SomeLargeADT
2525

26+
newtype PhantomADT e = PhantomADT ()
27+
deriving stock HS.Eq
28+
deriveEq ''PhantomADT
29+
2630
eqTests :: TestTree
2731
eqTests =
2832
let v1 :: SomeLargeADT () BuiltinString () () () = SomeLargeADT1 1 () Tx.True "foobar" () ()
@@ -36,6 +40,8 @@ eqTests =
3640
[testCase "reflexive1" $ (v1 Tx.== v1) @?= (v1 HS.== v1)
3741
, testCase "reflexive2" $ (v2 Tx.== v2) @?= (v2 HS.== v2)
3842
, testCase "reflexive3" $ (v3 Tx.== v3) @?= (v3 HS.== v3)
43+
-- currently does not work with polymorphic phantom types, remove the type annotation when support is added
44+
, testCase "phantom" $ (PhantomADT @() () Tx.== PhantomADT ()) @?= (PhantomADT () HS.== PhantomADT ())
3945
, testCase "shortcircuit" $ (v3 Tx.== v3Error1) @?= (v3 Tx.== v3Error1) -- should not throw an error
4046
, testCase "throws" $ try @SomeException (evaluate $ v3 Tx.== v3Error2) >>= assertBool "did not throw error" . isLeft -- should throw erro
4147
]

0 commit comments

Comments
 (0)