{-# 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)
{-# INLINABLE (/=) #-}

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

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

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

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

instance Eq Builtins.BuiltinBLS12_381_G1_Element where
    {-# INLINABLE (==) #-}
    == :: 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
    {-# INLINABLE (==) #-}
    == :: 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
    {-# INLINABLE (==) #-}
    [] == :: [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
    {-# INLINABLE (==) #-}
    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
    {-# INLINABLE (==) #-}
    (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
    {-# INLINABLE (==) #-}
    (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
    {-# INLINABLE (==) #-}
    ()
_ == :: () -> () -> Bool
== ()
_ = Bool
True

instance (Eq a, Eq b) => Eq (a, b) where
    {-# INLINABLE (==) #-}
    (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
    {-# INLINABLE (==) #-}
    (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