|
| 1 | +{-# LANGUAGE TemplateHaskell #-} |
1 | 2 | {-# OPTIONS_GHC -fno-omit-interface-pragmas #-} |
| 3 | +{-# OPTIONS_GHC -Wno-orphans #-} |
2 | 4 |
|
3 | | -module PlutusTx.Eq (Eq (..), (/=)) where |
| 5 | +module PlutusTx.Eq (Eq (..), (/=), deriveEq) where |
4 | 6 |
|
5 | 7 | import PlutusTx.Bool |
6 | 8 | import PlutusTx.Builtins qualified as Builtins |
7 | 9 | import PlutusTx.Either (Either (..)) |
| 10 | +import PlutusTx.Eq.TH |
8 | 11 | import Prelude (Maybe (..)) |
9 | 12 |
|
10 | 13 | {- HLINT ignore -} |
11 | 14 |
|
12 | | -infix 4 ==, /= |
13 | | - |
14 | | --- Copied from the GHC definition |
15 | | - |
16 | | --- | The 'Eq' class defines equality ('=='). |
17 | | -class Eq a where |
18 | | - (==) :: a -> a -> Bool |
19 | | - |
20 | | --- (/=) deliberately omitted, to make this a one-method class which has a |
21 | | --- simpler representation |
22 | | - |
| 15 | +infix 4 /= |
23 | 16 | (/=) :: (Eq a) => a -> a -> Bool |
24 | 17 | x /= y = not (x == y) |
25 | 18 | {-# INLINEABLE (/=) #-} |
@@ -48,34 +41,34 @@ instance Eq Builtins.BuiltinBLS12_381_G2_Element where |
48 | 41 | {-# INLINEABLE (==) #-} |
49 | 42 | (==) = Builtins.bls12_381_G2_equals |
50 | 43 |
|
51 | | -instance (Eq a) => Eq [a] where |
52 | | - {-# INLINEABLE (==) #-} |
53 | | - [] == [] = True |
54 | | - (x : xs) == (y : ys) = x == y && xs == ys |
55 | | - _ == _ = False |
56 | | - |
57 | | -instance Eq Bool where |
58 | | - {-# INLINEABLE (==) #-} |
59 | | - True == True = True |
60 | | - False == False = True |
61 | | - _ == _ = False |
62 | | - |
63 | | -instance (Eq a) => Eq (Maybe a) where |
64 | | - {-# INLINEABLE (==) #-} |
65 | | - (Just a1) == (Just a2) = a1 == a2 |
66 | | - Nothing == Nothing = True |
67 | | - _ == _ = False |
68 | | - |
69 | | -instance (Eq a, Eq b) => Eq (Either a b) where |
70 | | - {-# INLINEABLE (==) #-} |
71 | | - (Left a1) == (Left a2) = a1 == a2 |
72 | | - (Right b1) == (Right b2) = b1 == b2 |
73 | | - _ == _ = False |
74 | | - |
75 | | -instance Eq () where |
76 | | - {-# INLINEABLE (==) #-} |
77 | | - _ == _ = True |
78 | | - |
79 | | -instance (Eq a, Eq b) => Eq (a, b) where |
80 | | - {-# INLINEABLE (==) #-} |
81 | | - (a, b) == (a', b') = a == a' && b == b' |
| 44 | +deriveEq ''[] |
| 45 | +deriveEq ''Bool |
| 46 | +deriveEq ''Maybe |
| 47 | +deriveEq ''Either |
| 48 | +deriveEq ''() |
| 49 | +deriveEq ''(,) |
| 50 | +deriveEq ''(,,) |
| 51 | +deriveEq ''(,,,) |
| 52 | +deriveEq ''(,,,,) |
| 53 | +deriveEq ''(,,,,,) |
| 54 | +deriveEq ''(,,,,,,) |
| 55 | +deriveEq ''(,,,,,,,) |
| 56 | +deriveEq ''(,,,,,,,,) |
| 57 | +deriveEq ''(,,,,,,,,,) |
| 58 | +deriveEq ''(,,,,,,,,,,) |
| 59 | +deriveEq ''(,,,,,,,,,,,) |
| 60 | +deriveEq ''(,,,,,,,,,,,,) |
| 61 | +deriveEq ''(,,,,,,,,,,,,,) |
| 62 | +deriveEq ''(,,,,,,,,,,,,,,) |
| 63 | +deriveEq ''(,,,,,,,,,,,,,,,) |
| 64 | +deriveEq ''(,,,,,,,,,,,,,,,,) |
| 65 | +deriveEq ''(,,,,,,,,,,,,,,,,,) |
| 66 | +deriveEq ''(,,,,,,,,,,,,,,,,,,) |
| 67 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,) |
| 68 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,) |
| 69 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,,) |
| 70 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,,,) |
| 71 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,,,,) |
| 72 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,,,,,) |
| 73 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,,,,,,) |
| 74 | +deriveEq ''(,,,,,,,,,,,,,,,,,,,,,,,,,,) |
0 commit comments