module ZkFold.Symbolic.Data.Eq (
    Eq(..),
    elem
) where

import           Data.Bool                 (bool)
import           Data.Foldable             (Foldable)
import qualified Prelude                   as Haskell

import           ZkFold.Symbolic.Data.Bool (BoolType (..), any)

class BoolType b => Eq b a where
    infix 4 ==
    (==) :: a -> a -> b

    infix 4 /=
    (/=) :: a -> a -> b

instance {-# OVERLAPPABLE #-} (BoolType b, Haskell.Eq x) => Eq b x where
    x
x == :: x -> x -> b
== x
y = b -> b -> Bool -> b
forall a. a -> a -> Bool -> a
bool b
forall b. BoolType b => b
false b
forall b. BoolType b => b
true (x
x x -> x -> Bool
forall a. Eq a => a -> a -> Bool
Haskell.== x
y)
    x
x /= :: x -> x -> b
/= x
y = b -> b -> Bool -> b
forall a. a -> a -> Bool -> a
bool b
forall b. BoolType b => b
false b
forall b. BoolType b => b
true (x
x x -> x -> Bool
forall a. Eq a => a -> a -> Bool
Haskell./= x
y)

elem :: (Eq b a, Foldable t) => a -> t a -> b
elem :: forall b a (t :: Type -> Type).
(Eq b a, Foldable t) =>
a -> t a -> b
elem a
x = (a -> b) -> t a -> b
forall b (t :: Type -> Type) x.
(BoolType b, Foldable t) =>
(x -> b) -> t x -> b
any (a -> a -> b
forall b a. Eq b a => a -> a -> b
== a
x)