{-# LANGUAGE UndecidableInstances #-}

module ZkFold.Base.Protocol.Plonkup.LookupConstraint where

import           Data.Binary                                         (Binary)
import           Data.ByteString                                     (ByteString)
import           Data.Functor.Rep                                    (Rep)
import           Prelude                                             hiding (Num (..), drop, length, sum, take, (!!),
                                                                      (/), (^))
import           Test.QuickCheck                                     (Arbitrary (..))

import           ZkFold.Base.Data.ByteString                         (toByteString)
import           ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

newtype LookupConstraint i a = LookupConstraint { forall {k} (i :: Type -> Type) (a :: k).
LookupConstraint i a -> SysVar i
lkVar :: SysVar i }

deriving instance Show (Rep i) => Show (LookupConstraint i a)
deriving instance Eq (Rep i) => Eq (LookupConstraint i a)

instance (Arbitrary a, Binary a) => Arbitrary (LookupConstraint i a) where
    arbitrary :: Gen (LookupConstraint i a)
arbitrary = SysVar i -> LookupConstraint i a
forall {k} (i :: Type -> Type) (a :: k).
SysVar i -> LookupConstraint i a
LookupConstraint (SysVar i -> LookupConstraint i a)
-> (a -> SysVar i) -> a -> LookupConstraint i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> SysVar i
forall (i :: Type -> Type). ByteString -> SysVar i
NewVar (ByteString -> SysVar i) -> (a -> ByteString) -> a -> SysVar i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Binary a => a -> ByteString
toByteString @a (a -> LookupConstraint i a) -> Gen a -> Gen (LookupConstraint i a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
forall a. Arbitrary a => Gen a
arbitrary

toLookupConstraint :: forall a i . ByteString -> LookupConstraint i a
toLookupConstraint :: forall {k} (a :: k) (i :: Type -> Type).
ByteString -> LookupConstraint i a
toLookupConstraint = SysVar i -> LookupConstraint i a
forall {k} (i :: Type -> Type) (a :: k).
SysVar i -> LookupConstraint i a
LookupConstraint (SysVar i -> LookupConstraint i a)
-> (ByteString -> SysVar i) -> ByteString -> LookupConstraint i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> SysVar i
forall (i :: Type -> Type). ByteString -> SysVar i
NewVar