{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# OPTIONS_GHC -Wno-orphans #-}
--------------------------------------------------------------------------------
-- |
-- Module      :  HGeometry.Vector.Instances
-- Copyright   :  (C) Frank Staals
-- License     :  see the LICENSE file
-- Maintainer  :  Frank Staals
--
-- Arbitrary instances for the types in hgeometry-vector
--
--------------------------------------------------------------------------------
module HGeometry.Vector.Instances where

import Control.Lens
import HGeometry.Vector
import Test.QuickCheck

--------------------------------------------------------------------------------

instance (Arbitrary r, Vector_ (Vector d r) d r) => Arbitrary (Vector d r) where
  arbitrary :: Gen (Vector d r)
arbitrary = (Int -> Gen r) -> Gen (Vector d r)
forall vector (d :: Nat) r (f :: * -> *).
(Vector_ vector d r, Applicative f) =>
(Int -> f r) -> f vector
forall (f :: * -> *).
Applicative f =>
(Int -> f r) -> f (Vector d r)
generateA (Gen r -> Int -> Gen r
forall a b. a -> b -> a
const Gen r
forall a. Arbitrary a => Gen a
arbitrary)
  shrink :: Vector d r -> [Vector d r]
shrink Vector d r
v = [ Vector d r
vVector d r -> (Vector d r -> Vector d r) -> Vector d r
forall a b. a -> (a -> b) -> b
&Int -> IndexedTraversal' Int (Vector d r) r
forall vector (d :: Nat) r.
Vector_ vector d r =>
Int -> IndexedTraversal' Int vector r
component' Int
i ((r -> Identity r) -> Vector d r -> Identity (Vector d r))
-> r -> Vector d r -> Vector d r
forall s t a b. ASetter s t a b -> b -> s -> t
.~ r
x'
             | (Int
i,r
x) <- Vector d r
vVector d r
-> Getting (Endo [(Int, r)]) (Vector d r) (Int, r) -> [(Int, r)]
forall s a. s -> Getting (Endo [a]) s a -> [a]
^..Indexed Int r (Const (Endo [(Int, r)]) r)
-> Vector d r -> Const (Endo [(Int, r)]) (Vector d r)
Indexed
  Int
  (IxValue (Vector d r))
  (Const (Endo [(Int, r)]) (IxValue (Vector d r)))
-> Vector d r -> Const (Endo [(Int, r)]) (Vector d r)
forall vector vector'.
HasComponents vector vector' =>
IndexedTraversal1
  Int vector vector' (IxValue vector) (IxValue vector')
IndexedTraversal1
  Int
  (Vector d r)
  (Vector d r)
  (IxValue (Vector d r))
  (IxValue (Vector d r))
components(Indexed Int r (Const (Endo [(Int, r)]) r)
 -> Vector d r -> Const (Endo [(Int, r)]) (Vector d r))
-> (((Int, r) -> Const (Endo [(Int, r)]) (Int, r))
    -> Indexed Int r (Const (Endo [(Int, r)]) r))
-> Getting (Endo [(Int, r)]) (Vector d r) (Int, r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.((Int, r) -> Const (Endo [(Int, r)]) (Int, r))
-> Indexed Int r (Const (Endo [(Int, r)]) r)
forall i (p :: * -> * -> *) (f :: * -> *) s j t.
(Indexable i p, Functor f) =>
p (i, s) (f (j, t)) -> Indexed i s (f t)
withIndex
             , r
x' <- r -> [r]
forall a. Arbitrary a => a -> [a]
shrink r
x
             ]

-- instance ( forall r. VectorLike_ (Vector d r)
--          ) => Arbitrary1 (Vector d) where
--   liftArbitrary gen = generateA (const gen)
--   -- I think this instance is unreachable, so let's comment it for now.