module ZkFold.Symbolic.Data.DiscreteField where

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

import           ZkFold.Base.Algebra.Basic.Class
import           ZkFold.Symbolic.Class           (Arithmetic)
import           ZkFold.Symbolic.Data.Bool       (Bool (..), BoolType (..))
import           ZkFold.Symbolic.Interpreter     (Interpreter)

class (BoolType b, Field a) => DiscreteField b a where
    isZero :: a -> b

instance (Field a, Eq a) => DiscreteField Haskell.Bool a where
    isZero :: a -> Bool
isZero = (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. AdditiveMonoid a => a
zero)

instance (Arithmetic a, Field x, Eq x) => DiscreteField (Bool (Interpreter a)) x where
    isZero :: x -> Bool (Interpreter a)
isZero = Bool (Interpreter a)
-> Bool (Interpreter a) -> Bool -> Bool (Interpreter a)
forall a. a -> a -> Bool -> a
bool Bool (Interpreter a)
forall b. BoolType b => b
false Bool (Interpreter a)
forall b. BoolType b => b
true (Bool -> Bool (Interpreter a))
-> (x -> Bool) -> x -> Bool (Interpreter a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (x -> x -> Bool
forall a. Eq a => a -> a -> Bool
== x
forall a. AdditiveMonoid a => a
zero)