{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude, UndecidableInstances                    #-}
module Algebra.Ring.Ideal.Test () where
import           Algebra.Ring.Ideal     (Ideal, toIdeal)
import           AlgebraicPrelude       (DecidableZero, return, ($), (<$>))
import qualified Data.Foldable          as F
import           Test.QuickCheck        (Arbitrary (..))
import           Test.SmallCheck.Series (CoSerial (..), Serial (..),
                                         newtypeAlts, newtypeCons, (>>-))

instance (DecidableZero r, Arbitrary r) => Arbitrary (Ideal r) where
  arbitrary :: Gen (Ideal r)
arbitrary = [r] -> Ideal r
forall r. (DecidableZero r, Monoidal r) => [r] -> Ideal r
toIdeal ([r] -> Ideal r) -> Gen [r] -> Gen (Ideal r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [r]
forall a. Arbitrary a => Gen a
arbitrary

instance (DecidableZero r, Serial m r) => Serial m (Ideal r) where
  series :: Series m (Ideal r)
series = ([r] -> Ideal r) -> Series m (Ideal r)
forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons [r] -> Ideal r
forall r. (DecidableZero r, Monoidal r) => [r] -> Ideal r
toIdeal

instance (CoSerial m r) => CoSerial m (Ideal r) where
  coseries :: Series m b -> Series m (Ideal r -> b)
coseries Series m b
rs =
    Series m b -> Series m ([r] -> b)
forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs Series m ([r] -> b)
-> (([r] -> b) -> Series m (Ideal r -> b))
-> Series m (Ideal r -> b)
forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \[r] -> b
f ->
      (Ideal r -> b) -> Series m (Ideal r -> b)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Ideal r -> b) -> Series m (Ideal r -> b))
-> (Ideal r -> b) -> Series m (Ideal r -> b)
forall a b. (a -> b) -> a -> b
$ \Ideal r
l -> [r] -> b
f (Ideal r -> [r]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList Ideal r
l)