{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}

module PlutusTx.Eq (Eq (..), (/=)) where

import PlutusTx.Bool
import PlutusTx.Builtins qualified as Builtins
import PlutusTx.Either (Either (..))
import PlutusTx.These
import Prelude (Maybe (..))

{- HLINT ignore -}

infix 4 ==, /=

-- Copied from the GHC definition

-- | The 'Eq' class defines equality ('==').
class Eq a where
  (==) :: a -> a -> Bool

-- (/=) deliberately omitted, to make this a one-method class which has a
-- simpler representation

(/=) :: (Eq a) => a -> a -> Bool
a
x /= :: forall a. Eq a => a -> a -> Bool
/= a
y = Bool -> Bool
not (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y)
{-# INLINEABLE (/=) #-}

instance Eq Builtins.Integer where
  {-# INLINEABLE (==) #-}
  == :: Integer -> Integer -> Bool
(==) = Integer -> Integer -> Bool
Builtins.equalsInteger

instance Eq Builtins.BuiltinByteString where
  {-# INLINEABLE (==) #-}
  == :: BuiltinByteString -> BuiltinByteString -> Bool
(==) = BuiltinByteString -> BuiltinByteString -> Bool
Builtins.equalsByteString

instance Eq Builtins.BuiltinData where
  {-# INLINEABLE (==) #-}
  == :: BuiltinData -> BuiltinData -> Bool
(==) = BuiltinData -> BuiltinData -> Bool
Builtins.equalsData

instance Eq Builtins.BuiltinString where
  {-# INLINEABLE (==) #-}
  == :: BuiltinString -> BuiltinString -> Bool
(==) = BuiltinString -> BuiltinString -> Bool
Builtins.equalsString

instance Eq Builtins.BuiltinBLS12_381_G1_Element where
  {-# INLINEABLE (==) #-}
  == :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element -> Bool
(==) = BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element -> Bool
Builtins.bls12_381_G1_equals

instance Eq Builtins.BuiltinBLS12_381_G2_Element where
  {-# INLINEABLE (==) #-}
  == :: BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element -> Bool
(==) = BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element -> Bool
Builtins.bls12_381_G2_equals

instance (Eq a) => Eq [a] where
  {-# INLINEABLE (==) #-}
  [] == :: [a] -> [a] -> Bool
== []             = Bool
True
  (a
x : [a]
xs) == (a
y : [a]
ys) = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& [a]
xs [a] -> [a] -> Bool
forall a. Eq a => a -> a -> Bool
== [a]
ys
  [a]
_ == [a]
_               = Bool
False

instance Eq Bool where
  {-# INLINEABLE (==) #-}
  Bool
True == :: Bool -> Bool -> Bool
== Bool
True   = Bool
True
  Bool
False == Bool
False = Bool
True
  Bool
_ == Bool
_         = Bool
False

instance (Eq a) => Eq (Maybe a) where
  {-# INLINEABLE (==) #-}
  (Just a
a1) == :: Maybe a -> Maybe a -> Bool
== (Just a
a2) = a
a1 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a2
  Maybe a
Nothing == Maybe a
Nothing     = Bool
True
  Maybe a
_ == Maybe a
_                 = Bool
False

instance (Eq a, Eq b) => Eq (Either a b) where
  {-# INLINEABLE (==) #-}
  (Left a
a1) == :: Either a b -> Either a b -> Bool
== (Left a
a2)   = a
a1 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a2
  (Right b
b1) == (Right b
b2) = b
b1 b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
b2
  Either a b
_ == Either a b
_                   = Bool
False

instance Eq () where
  {-# INLINEABLE (==) #-}
  ()
_ == :: () -> () -> Bool
== ()
_ = Bool
True

instance (Eq a, Eq b) => Eq (a, b) where
  {-# INLINEABLE (==) #-}
  (a
a, b
b) == :: (a, b) -> (a, b) -> Bool
== (a
a', b
b') = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a' Bool -> Bool -> Bool
&& b
b b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
b'

instance (Eq a, Eq b) => Eq (These a b) where
  {-# INLINEABLE (==) #-}
  (This a
a) == :: These a b -> These a b -> Bool
== (This a
a')        = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a'
  (That b
b) == (That b
b')        = b
b b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
b'
  (These a
a b
b) == (These a
a' b
b') = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a' Bool -> Bool -> Bool
&& b
b b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
b'
  These a b
_ == These a b
_                       = Bool
False