{-# LANGUAGE BangPatterns, CPP, MultiParamTypeClasses, TypeFamilies, FlexibleContexts #-}
#if __GLASGOW_HASKELL__ >= 707
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
#endif
#if __GLASGOW_HASKELL__ >= 706
{-# LANGUAGE PolyKinds #-}
#endif
{-# OPTIONS_HADDOCK hide #-}

-- |
-- Module      : Data.Vector.Unboxed.Base
-- Copyright   : (c) Roman Leshchinskiy 2009-2010
-- License     : BSD-style
--
-- Maintainer  : Roman Leshchinskiy <rl@cse.unsw.edu.au>
-- Stability   : experimental
-- Portability : non-portable
--
-- Adaptive unboxed vectors: basic implementation
--

module Data.Vector.Unboxed.Base (
  MVector(..), IOVector, STVector, Vector(..), Unbox
) where

import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as M

import qualified Data.Vector.Primitive as P

import Control.Applicative (Const(..))

import Control.DeepSeq ( NFData(rnf)
#if MIN_VERSION_deepseq(1,4,3)
                       , NFData1(liftRnf)
#endif
                       )

import Control.Monad.Primitive
import Control.Monad ( liftM )

#if MIN_VERSION_base(4,8,0)
import Data.Functor.Identity
#endif
#if MIN_VERSION_base(4,9,0)
import Data.Functor.Compose
#endif

import Data.Word ( Word8, Word16, Word32, Word64 )
import Data.Int  ( Int8, Int16, Int32, Int64 )
import Data.Complex
import Data.Monoid (Dual(..),Sum(..),Product(..),All(..),Any(..))
#if MIN_VERSION_base(4,8,0)
import Data.Monoid (Alt(..))
#endif
#if MIN_VERSION_base(4,9,0)
import Data.Semigroup (Min(..),Max(..),First(..),Last(..),WrappedMonoid(..),Arg(..))
#endif
#if !MIN_VERSION_base(4,8,0)
import Data.Word ( Word )
#endif

#if __GLASGOW_HASKELL__ >= 707
import Data.Typeable ( Typeable )
#else
import Data.Typeable ( Typeable1(..), Typeable2(..), mkTyConApp,
                       mkTyCon3
                     )
#endif
import Data.Data     ( Data(..) )
import GHC.Exts      ( Down(..) )

-- Data.Vector.Internal.Check is unused
#define NOT_VECTOR_MODULE
#include "vector.h"

data family MVector s a
data family Vector    a

type IOVector = MVector RealWorld
type STVector s = MVector s

type instance G.Mutable Vector = MVector

class (G.Vector Vector a, M.MVector MVector a) => Unbox a

instance NFData (Vector a) where rnf :: Vector a -> ()
rnf !Vector a
_ = ()
instance NFData (MVector s a) where rnf :: MVector s a -> ()
rnf !MVector s a
_ = ()

#if MIN_VERSION_deepseq(1,4,3)
-- | @since 0.12.1.0
instance NFData1 Vector where
  liftRnf :: (a -> ()) -> Vector a -> ()
liftRnf a -> ()
_ !Vector a
_ = ()
-- | @since 0.12.1.0
instance NFData1 (MVector s) where
  liftRnf :: (a -> ()) -> MVector s a -> ()
liftRnf a -> ()
_ !MVector s a
_ = ()
#endif

-- -----------------
-- Data and Typeable
-- -----------------
#if __GLASGOW_HASKELL__ >= 707
deriving instance Typeable Vector
deriving instance Typeable MVector
#else
vectorTyCon = mkTyCon3 "vector"

instance Typeable1 Vector where
  typeOf1 _ = mkTyConApp (vectorTyCon "Data.Vector.Unboxed" "Vector") []

instance Typeable2 MVector where
  typeOf2 _ = mkTyConApp (vectorTyCon "Data.Vector.Unboxed.Mutable" "MVector") []
#endif

instance (Data a, Unbox a) => Data (Vector a) where
  gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector a -> c (Vector a)
gfoldl       = (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector a -> c (Vector a)
forall (v :: * -> *) a (c :: * -> *).
(Vector v a, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> v a -> c (v a)
G.gfoldl
  toConstr :: Vector a -> Constr
toConstr Vector a
_   = String -> Constr
G.mkVecConstr String
"Data.Vector.Unboxed.Vector"
  gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector a)
gunfold      = (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector a)
forall (v :: * -> *) a (c :: * -> *).
(Vector v a, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (v a)
G.gunfold
  dataTypeOf :: Vector a -> DataType
dataTypeOf Vector a
_ = String -> DataType
G.mkVecType String
"Data.Vector.Unboxed.Vector"
  dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Vector a))
dataCast1    = (forall d. Data d => c (t d)) -> Maybe (c (Vector a))
forall (v :: * -> *) a (t :: * -> *) (c :: * -> *).
(Vector v a, Data a, Typeable v, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (v a))
G.dataCast

-- ----
-- Unit
-- ----

newtype instance MVector s () = MV_Unit Int
newtype instance Vector    () = V_Unit Int

instance Unbox ()

instance M.MVector MVector () where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}

  basicLength :: MVector s () -> Int
basicLength (MV_Unit n) = Int
n

  basicUnsafeSlice :: Int -> Int -> MVector s () -> MVector s ()
basicUnsafeSlice Int
_ Int
m (MV_Unit _) = Int -> MVector s ()
forall s. Int -> MVector s ()
MV_Unit Int
m

  basicOverlaps :: MVector s () -> MVector s () -> Bool
basicOverlaps MVector s ()
_ MVector s ()
_ = Bool
False

  basicUnsafeNew :: Int -> m (MVector (PrimState m) ())
basicUnsafeNew Int
n = MVector (PrimState m) () -> m (MVector (PrimState m) ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> MVector (PrimState m) ()
forall s. Int -> MVector s ()
MV_Unit Int
n)

  -- Nothing to initialize
  basicInitialize :: MVector (PrimState m) () -> m ()
basicInitialize MVector (PrimState m) ()
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeRead :: MVector (PrimState m) () -> Int -> m ()
basicUnsafeRead (MV_Unit _) Int
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeWrite :: MVector (PrimState m) () -> Int -> () -> m ()
basicUnsafeWrite (MV_Unit _) Int
_ () = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicClear :: MVector (PrimState m) () -> m ()
basicClear MVector (PrimState m) ()
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicSet :: MVector (PrimState m) () -> () -> m ()
basicSet (MV_Unit _) () = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeCopy :: MVector (PrimState m) () -> MVector (PrimState m) () -> m ()
basicUnsafeCopy (MV_Unit _) (MV_Unit _) = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeGrow :: MVector (PrimState m) () -> Int -> m (MVector (PrimState m) ())
basicUnsafeGrow (MV_Unit n) Int
m = MVector (PrimState m) () -> m (MVector (PrimState m) ())
forall (m :: * -> *) a. Monad m => a -> m a
return (MVector (PrimState m) () -> m (MVector (PrimState m) ()))
-> MVector (PrimState m) () -> m (MVector (PrimState m) ())
forall a b. (a -> b) -> a -> b
$ Int -> MVector (PrimState m) ()
forall s. Int -> MVector s ()
MV_Unit (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
m)

instance G.Vector Vector () where
  {-# INLINE basicUnsafeFreeze #-}
  basicUnsafeFreeze :: Mutable Vector (PrimState m) () -> m (Vector ())
basicUnsafeFreeze (MV_Unit n) = Vector () -> m (Vector ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector () -> m (Vector ())) -> Vector () -> m (Vector ())
forall a b. (a -> b) -> a -> b
$ Int -> Vector ()
V_Unit Int
n

  {-# INLINE basicUnsafeThaw #-}
  basicUnsafeThaw :: Vector () -> m (Mutable Vector (PrimState m) ())
basicUnsafeThaw (V_Unit n) = MVector (PrimState m) () -> m (MVector (PrimState m) ())
forall (m :: * -> *) a. Monad m => a -> m a
return (MVector (PrimState m) () -> m (MVector (PrimState m) ()))
-> MVector (PrimState m) () -> m (MVector (PrimState m) ())
forall a b. (a -> b) -> a -> b
$ Int -> MVector (PrimState m) ()
forall s. Int -> MVector s ()
MV_Unit Int
n

  {-# INLINE basicLength #-}
  basicLength :: Vector () -> Int
basicLength (V_Unit n) = Int
n

  {-# INLINE basicUnsafeSlice #-}
  basicUnsafeSlice :: Int -> Int -> Vector () -> Vector ()
basicUnsafeSlice Int
_ Int
m (V_Unit _) = Int -> Vector ()
V_Unit Int
m

  {-# INLINE basicUnsafeIndexM #-}
  basicUnsafeIndexM :: Vector () -> Int -> m ()
basicUnsafeIndexM (V_Unit _) Int
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  {-# INLINE basicUnsafeCopy #-}
  basicUnsafeCopy :: Mutable Vector (PrimState m) () -> Vector () -> m ()
basicUnsafeCopy (MV_Unit _) (V_Unit _) = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  {-# INLINE elemseq #-}
  elemseq :: Vector () -> () -> b -> b
elemseq Vector ()
_ = () -> b -> b
seq


-- ---------------
-- Primitive types
-- ---------------

#define primMVector(ty,con)                                             \
instance M.MVector MVector ty where {                                   \
  {-# INLINE basicLength #-}                                            \
; {-# INLINE basicUnsafeSlice #-}                                       \
; {-# INLINE basicOverlaps #-}                                          \
; {-# INLINE basicUnsafeNew #-}                                         \
; {-# INLINE basicInitialize #-}                                        \
; {-# INLINE basicUnsafeReplicate #-}                                   \
; {-# INLINE basicUnsafeRead #-}                                        \
; {-# INLINE basicUnsafeWrite #-}                                       \
; {-# INLINE basicClear #-}                                             \
; {-# INLINE basicSet #-}                                               \
; {-# INLINE basicUnsafeCopy #-}                                        \
; {-# INLINE basicUnsafeGrow #-}                                        \
; basicLength (con v) = M.basicLength v                                 \
; basicUnsafeSlice i n (con v) = con $ M.basicUnsafeSlice i n v         \
; basicOverlaps (con v1) (con v2) = M.basicOverlaps v1 v2               \
; basicUnsafeNew n = con `liftM` M.basicUnsafeNew n                     \
; basicInitialize (con v) = M.basicInitialize v                         \
; basicUnsafeReplicate n x = con `liftM` M.basicUnsafeReplicate n x     \
; basicUnsafeRead (con v) i = M.basicUnsafeRead v i                     \
; basicUnsafeWrite (con v) i x = M.basicUnsafeWrite v i x               \
; basicClear (con v) = M.basicClear v                                   \
; basicSet (con v) x = M.basicSet v x                                   \
; basicUnsafeCopy (con v1) (con v2) = M.basicUnsafeCopy v1 v2           \
; basicUnsafeMove (con v1) (con v2) = M.basicUnsafeMove v1 v2           \
; basicUnsafeGrow (con v) n = con `liftM` M.basicUnsafeGrow v n }

#define primVector(ty,con,mcon)                                         \
instance G.Vector Vector ty where {                                     \
  {-# INLINE basicUnsafeFreeze #-}                                      \
; {-# INLINE basicUnsafeThaw #-}                                        \
; {-# INLINE basicLength #-}                                            \
; {-# INLINE basicUnsafeSlice #-}                                       \
; {-# INLINE basicUnsafeIndexM #-}                                      \
; {-# INLINE elemseq #-}                                                \
; basicUnsafeFreeze (mcon v) = con `liftM` G.basicUnsafeFreeze v        \
; basicUnsafeThaw (con v) = mcon `liftM` G.basicUnsafeThaw v            \
; basicLength (con v) = G.basicLength v                                 \
; basicUnsafeSlice i n (con v) = con $ G.basicUnsafeSlice i n v         \
; basicUnsafeIndexM (con v) i = G.basicUnsafeIndexM v i                 \
; basicUnsafeCopy (mcon mv) (con v) = G.basicUnsafeCopy mv v            \
; elemseq _ = seq }

newtype instance MVector s Int = MV_Int (P.MVector s Int)
newtype instance Vector    Int = V_Int  (P.Vector    Int)
instance Unbox Int
primMVector(Int, MV_Int)
primVector(Int, V_Int, MV_Int)

newtype instance MVector s Int8 = MV_Int8 (P.MVector s Int8)
newtype instance Vector    Int8 = V_Int8  (P.Vector    Int8)
instance Unbox Int8
primMVector(Int8, MV_Int8)
primVector(Int8, V_Int8, MV_Int8)

newtype instance MVector s Int16 = MV_Int16 (P.MVector s Int16)
newtype instance Vector    Int16 = V_Int16  (P.Vector    Int16)
instance Unbox Int16
primMVector(Int16, MV_Int16)
primVector(Int16, V_Int16, MV_Int16)

newtype instance MVector s Int32 = MV_Int32 (P.MVector s Int32)
newtype instance Vector    Int32 = V_Int32  (P.Vector    Int32)
instance Unbox Int32
primMVector(Int32, MV_Int32)
primVector(Int32, V_Int32, MV_Int32)

newtype instance MVector s Int64 = MV_Int64 (P.MVector s Int64)
newtype instance Vector    Int64 = V_Int64  (P.Vector    Int64)
instance Unbox Int64
primMVector(Int64, MV_Int64)
primVector(Int64, V_Int64, MV_Int64)


newtype instance MVector s Word = MV_Word (P.MVector s Word)
newtype instance Vector    Word = V_Word  (P.Vector    Word)
instance Unbox Word
primMVector(Word, MV_Word)
primVector(Word, V_Word, MV_Word)

newtype instance MVector s Word8 = MV_Word8 (P.MVector s Word8)
newtype instance Vector    Word8 = V_Word8  (P.Vector    Word8)
instance Unbox Word8
primMVector(Word8, MV_Word8)
primVector(Word8, V_Word8, MV_Word8)

newtype instance MVector s Word16 = MV_Word16 (P.MVector s Word16)
newtype instance Vector    Word16 = V_Word16  (P.Vector    Word16)
instance Unbox Word16
primMVector(Word16, MV_Word16)
primVector(Word16, V_Word16, MV_Word16)

newtype instance MVector s Word32 = MV_Word32 (P.MVector s Word32)
newtype instance Vector    Word32 = V_Word32  (P.Vector    Word32)
instance Unbox Word32
primMVector(Word32, MV_Word32)
primVector(Word32, V_Word32, MV_Word32)

newtype instance MVector s Word64 = MV_Word64 (P.MVector s Word64)
newtype instance Vector    Word64 = V_Word64  (P.Vector    Word64)
instance Unbox Word64
primMVector(Word64, MV_Word64)
primVector(Word64, V_Word64, MV_Word64)


newtype instance MVector s Float = MV_Float (P.MVector s Float)
newtype instance Vector    Float = V_Float  (P.Vector    Float)
instance Unbox Float
primMVector(Float, MV_Float)
primVector(Float, V_Float, MV_Float)

newtype instance MVector s Double = MV_Double (P.MVector s Double)
newtype instance Vector    Double = V_Double  (P.Vector    Double)
instance Unbox Double
primMVector(Double, MV_Double)
primVector(Double, V_Double, MV_Double)


newtype instance MVector s Char = MV_Char (P.MVector s Char)
newtype instance Vector    Char = V_Char  (P.Vector    Char)
instance Unbox Char
primMVector(Char, MV_Char)
primVector(Char, V_Char, MV_Char)

-- ----
-- Bool
-- ----

fromBool :: Bool -> Word8
{-# INLINE fromBool #-}
fromBool :: Bool -> Word8
fromBool Bool
True = Word8
1
fromBool Bool
False = Word8
0

toBool :: Word8 -> Bool
{-# INLINE toBool #-}
toBool :: Word8 -> Bool
toBool Word8
0 = Bool
False
toBool Word8
_ = Bool
True

newtype instance MVector s Bool = MV_Bool (P.MVector s Word8)
newtype instance Vector    Bool = V_Bool  (P.Vector    Word8)

instance Unbox Bool

instance M.MVector MVector Bool where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: MVector s Bool -> Int
basicLength (MV_Bool v) = MVector s Word8 -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength MVector s Word8
v
  basicUnsafeSlice :: Int -> Int -> MVector s Bool -> MVector s Bool
basicUnsafeSlice Int
i Int
n (MV_Bool v) = MVector s Word8 -> MVector s Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector s Word8 -> MVector s Bool)
-> MVector s Word8 -> MVector s Bool
forall a b. (a -> b) -> a -> b
$ Int -> Int -> MVector s Word8 -> MVector s Word8
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice Int
i Int
n MVector s Word8
v
  basicOverlaps :: MVector s Bool -> MVector s Bool -> Bool
basicOverlaps (MV_Bool v1) (MV_Bool v2) = MVector s Word8 -> MVector s Word8 -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps MVector s Word8
v1 MVector s Word8
v2
  basicUnsafeNew :: Int -> m (MVector (PrimState m) Bool)
basicUnsafeNew Int
n = MVector (PrimState m) Word8 -> MVector (PrimState m) Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector (PrimState m) Word8 -> MVector (PrimState m) Bool)
-> m (MVector (PrimState m) Word8)
-> m (MVector (PrimState m) Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> m (MVector (PrimState m) Word8)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> m (v (PrimState m) a)
M.basicUnsafeNew Int
n
  basicInitialize :: MVector (PrimState m) Bool -> m ()
basicInitialize (MV_Bool v) = MVector (PrimState m) Word8 -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicInitialize MVector (PrimState m) Word8
v
  basicUnsafeReplicate :: Int -> Bool -> m (MVector (PrimState m) Bool)
basicUnsafeReplicate Int
n Bool
x = MVector (PrimState m) Word8 -> MVector (PrimState m) Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector (PrimState m) Word8 -> MVector (PrimState m) Bool)
-> m (MVector (PrimState m) Word8)
-> m (MVector (PrimState m) Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> Word8 -> m (MVector (PrimState m) Word8)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> a -> m (v (PrimState m) a)
M.basicUnsafeReplicate Int
n (Bool -> Word8
fromBool Bool
x)
  basicUnsafeRead :: MVector (PrimState m) Bool -> Int -> m Bool
basicUnsafeRead (MV_Bool v) Int
i = Word8 -> Bool
toBool (Word8 -> Bool) -> m Word8 -> m Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector (PrimState m) Word8 -> Int -> m Word8
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
M.basicUnsafeRead MVector (PrimState m) Word8
v Int
i
  basicUnsafeWrite :: MVector (PrimState m) Bool -> Int -> Bool -> m ()
basicUnsafeWrite (MV_Bool v) Int
i Bool
x = MVector (PrimState m) Word8 -> Int -> Word8 -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
M.basicUnsafeWrite MVector (PrimState m) Word8
v Int
i (Bool -> Word8
fromBool Bool
x)
  basicClear :: MVector (PrimState m) Bool -> m ()
basicClear (MV_Bool v) = MVector (PrimState m) Word8 -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicClear MVector (PrimState m) Word8
v
  basicSet :: MVector (PrimState m) Bool -> Bool -> m ()
basicSet (MV_Bool v) Bool
x = MVector (PrimState m) Word8 -> Word8 -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> a -> m ()
M.basicSet MVector (PrimState m) Word8
v (Bool -> Word8
fromBool Bool
x)
  basicUnsafeCopy :: MVector (PrimState m) Bool -> MVector (PrimState m) Bool -> m ()
basicUnsafeCopy (MV_Bool v1) (MV_Bool v2) = MVector (PrimState m) Word8 -> MVector (PrimState m) Word8 -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
M.basicUnsafeCopy MVector (PrimState m) Word8
v1 MVector (PrimState m) Word8
v2
  basicUnsafeMove :: MVector (PrimState m) Bool -> MVector (PrimState m) Bool -> m ()
basicUnsafeMove (MV_Bool v1) (MV_Bool v2) = MVector (PrimState m) Word8 -> MVector (PrimState m) Word8 -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
M.basicUnsafeMove MVector (PrimState m) Word8
v1 MVector (PrimState m) Word8
v2
  basicUnsafeGrow :: MVector (PrimState m) Bool -> Int -> m (MVector (PrimState m) Bool)
basicUnsafeGrow (MV_Bool v) Int
n = MVector (PrimState m) Word8 -> MVector (PrimState m) Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector (PrimState m) Word8 -> MVector (PrimState m) Bool)
-> m (MVector (PrimState m) Word8)
-> m (MVector (PrimState m) Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector (PrimState m) Word8
-> Int -> m (MVector (PrimState m) Word8)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
M.basicUnsafeGrow MVector (PrimState m) Word8
v Int
n

instance G.Vector Vector Bool where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeFreeze :: Mutable Vector (PrimState m) Bool -> m (Vector Bool)
basicUnsafeFreeze (MV_Bool v) = Vector Word8 -> Vector Bool
V_Bool (Vector Word8 -> Vector Bool)
-> m (Vector Word8) -> m (Vector Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Mutable Vector (PrimState m) Word8 -> m (Vector Word8)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> m (v a)
G.basicUnsafeFreeze Mutable Vector (PrimState m) Word8
MVector (PrimState m) Word8
v
  basicUnsafeThaw :: Vector Bool -> m (Mutable Vector (PrimState m) Bool)
basicUnsafeThaw (V_Bool v) = MVector (PrimState m) Word8 -> MVector (PrimState m) Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector (PrimState m) Word8 -> MVector (PrimState m) Bool)
-> m (MVector (PrimState m) Word8)
-> m (MVector (PrimState m) Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector Word8 -> m (Mutable Vector (PrimState m) Word8)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
v a -> m (Mutable v (PrimState m) a)
G.basicUnsafeThaw Vector Word8
v
  basicLength :: Vector Bool -> Int
basicLength (V_Bool v) = Vector Word8 -> Int
forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength Vector Word8
v
  basicUnsafeSlice :: Int -> Int -> Vector Bool -> Vector Bool
basicUnsafeSlice Int
i Int
n (V_Bool v) = Vector Word8 -> Vector Bool
V_Bool (Vector Word8 -> Vector Bool) -> Vector Word8 -> Vector Bool
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Vector Word8 -> Vector Word8
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice Int
i Int
n Vector Word8
v
  basicUnsafeIndexM :: Vector Bool -> Int -> m Bool
basicUnsafeIndexM (V_Bool v) Int
i = Word8 -> Bool
toBool (Word8 -> Bool) -> m Word8 -> m Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector Word8 -> Int -> m Word8
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
G.basicUnsafeIndexM Vector Word8
v Int
i
  basicUnsafeCopy :: Mutable Vector (PrimState m) Bool -> Vector Bool -> m ()
basicUnsafeCopy (MV_Bool mv) (V_Bool v) = Mutable Vector (PrimState m) Word8 -> Vector Word8 -> m ()
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> v a -> m ()
G.basicUnsafeCopy Mutable Vector (PrimState m) Word8
MVector (PrimState m) Word8
mv Vector Word8
v
  elemseq :: Vector Bool -> Bool -> b -> b
elemseq Vector Bool
_ = Bool -> b -> b
seq

-- -------
-- Complex
-- -------

newtype instance MVector s (Complex a) = MV_Complex (MVector s (a,a))
newtype instance Vector    (Complex a) = V_Complex  (Vector    (a,a))

instance (Unbox a) => Unbox (Complex a)

instance (Unbox a) => M.MVector MVector (Complex a) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: MVector s (Complex a) -> Int
basicLength (MV_Complex v) = MVector s (a, a) -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength MVector s (a, a)
v
  basicUnsafeSlice :: Int -> Int -> MVector s (Complex a) -> MVector s (Complex a)
basicUnsafeSlice Int
i Int
n (MV_Complex v) = MVector s (a, a) -> MVector s (Complex a)
forall s a. MVector s (a, a) -> MVector s (Complex a)
MV_Complex (MVector s (a, a) -> MVector s (Complex a))
-> MVector s (a, a) -> MVector s (Complex a)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> MVector s (a, a) -> MVector s (a, a)
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice Int
i Int
n MVector s (a, a)
v
  basicOverlaps :: MVector s (Complex a) -> MVector s (Complex a) -> Bool
basicOverlaps (MV_Complex v1) (MV_Complex v2) = MVector s (a, a) -> MVector s (a, a) -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps MVector s (a, a)
v1 MVector s (a, a)
v2
  basicUnsafeNew :: Int -> m (MVector (PrimState m) (Complex a))
basicUnsafeNew Int
n = MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a)
forall s a. MVector s (a, a) -> MVector s (Complex a)
MV_Complex (MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a))
-> m (MVector (PrimState m) (a, a))
-> m (MVector (PrimState m) (Complex a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> m (MVector (PrimState m) (a, a))
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> m (v (PrimState m) a)
M.basicUnsafeNew Int
n
  basicInitialize :: MVector (PrimState m) (Complex a) -> m ()
basicInitialize (MV_Complex v) = MVector (PrimState m) (a, a) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicInitialize MVector (PrimState m) (a, a)
v
  basicUnsafeReplicate :: Int -> Complex a -> m (MVector (PrimState m) (Complex a))
basicUnsafeReplicate Int
n (a
x :+ a
y) = MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a)
forall s a. MVector s (a, a) -> MVector s (Complex a)
MV_Complex (MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a))
-> m (MVector (PrimState m) (a, a))
-> m (MVector (PrimState m) (Complex a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> (a, a) -> m (MVector (PrimState m) (a, a))
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> a -> m (v (PrimState m) a)
M.basicUnsafeReplicate Int
n (a
x,a
y)
  basicUnsafeRead :: MVector (PrimState m) (Complex a) -> Int -> m (Complex a)
basicUnsafeRead (MV_Complex v) Int
i = (a -> a -> Complex a) -> (a, a) -> Complex a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Complex a
forall a. a -> a -> Complex a
(:+) ((a, a) -> Complex a) -> m (a, a) -> m (Complex a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector (PrimState m) (a, a) -> Int -> m (a, a)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
M.basicUnsafeRead MVector (PrimState m) (a, a)
v Int
i
  basicUnsafeWrite :: MVector (PrimState m) (Complex a) -> Int -> Complex a -> m ()
basicUnsafeWrite (MV_Complex v) Int
i (a
x :+ a
y) = MVector (PrimState m) (a, a) -> Int -> (a, a) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
M.basicUnsafeWrite MVector (PrimState m) (a, a)
v Int
i (a
x,a
y)
  basicClear :: MVector (PrimState m) (Complex a) -> m ()
basicClear (MV_Complex v) = MVector (PrimState m) (a, a) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicClear MVector (PrimState m) (a, a)
v
  basicSet :: MVector (PrimState m) (Complex a) -> Complex a -> m ()
basicSet (MV_Complex v) (a
x :+ a
y) = MVector (PrimState m) (a, a) -> (a, a) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> a -> m ()
M.basicSet MVector (PrimState m) (a, a)
v (a
x,a
y)
  basicUnsafeCopy :: MVector (PrimState m) (Complex a)
-> MVector (PrimState m) (Complex a) -> m ()
basicUnsafeCopy (MV_Complex v1) (MV_Complex v2) = MVector (PrimState m) (a, a)
-> MVector (PrimState m) (a, a) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
M.basicUnsafeCopy MVector (PrimState m) (a, a)
v1 MVector (PrimState m) (a, a)
v2
  basicUnsafeMove :: MVector (PrimState m) (Complex a)
-> MVector (PrimState m) (Complex a) -> m ()
basicUnsafeMove (MV_Complex v1) (MV_Complex v2) = MVector (PrimState m) (a, a)
-> MVector (PrimState m) (a, a) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
M.basicUnsafeMove MVector (PrimState m) (a, a)
v1 MVector (PrimState m) (a, a)
v2
  basicUnsafeGrow :: MVector (PrimState m) (Complex a)
-> Int -> m (MVector (PrimState m) (Complex a))
basicUnsafeGrow (MV_Complex v) Int
n = MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a)
forall s a. MVector s (a, a) -> MVector s (Complex a)
MV_Complex (MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a))
-> m (MVector (PrimState m) (a, a))
-> m (MVector (PrimState m) (Complex a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector (PrimState m) (a, a)
-> Int -> m (MVector (PrimState m) (a, a))
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
M.basicUnsafeGrow MVector (PrimState m) (a, a)
v Int
n

instance (Unbox a) => G.Vector Vector (Complex a) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeFreeze :: Mutable Vector (PrimState m) (Complex a) -> m (Vector (Complex a))
basicUnsafeFreeze (MV_Complex v) = Vector (a, a) -> Vector (Complex a)
forall a. Vector (a, a) -> Vector (Complex a)
V_Complex (Vector (a, a) -> Vector (Complex a))
-> m (Vector (a, a)) -> m (Vector (Complex a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Mutable Vector (PrimState m) (a, a) -> m (Vector (a, a))
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> m (v a)
G.basicUnsafeFreeze Mutable Vector (PrimState m) (a, a)
MVector (PrimState m) (a, a)
v
  basicUnsafeThaw :: Vector (Complex a) -> m (Mutable Vector (PrimState m) (Complex a))
basicUnsafeThaw (V_Complex v) = MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a)
forall s a. MVector s (a, a) -> MVector s (Complex a)
MV_Complex (MVector (PrimState m) (a, a) -> MVector (PrimState m) (Complex a))
-> m (MVector (PrimState m) (a, a))
-> m (MVector (PrimState m) (Complex a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector (a, a) -> m (Mutable Vector (PrimState m) (a, a))
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
v a -> m (Mutable v (PrimState m) a)
G.basicUnsafeThaw Vector (a, a)
v
  basicLength :: Vector (Complex a) -> Int
basicLength (V_Complex v) = Vector (a, a) -> Int
forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength Vector (a, a)
v
  basicUnsafeSlice :: Int -> Int -> Vector (Complex a) -> Vector (Complex a)
basicUnsafeSlice Int
i Int
n (V_Complex v) = Vector (a, a) -> Vector (Complex a)
forall a. Vector (a, a) -> Vector (Complex a)
V_Complex (Vector (a, a) -> Vector (Complex a))
-> Vector (a, a) -> Vector (Complex a)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Vector (a, a) -> Vector (a, a)
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice Int
i Int
n Vector (a, a)
v
  basicUnsafeIndexM :: Vector (Complex a) -> Int -> m (Complex a)
basicUnsafeIndexM (V_Complex v) Int
i
                = (a -> a -> Complex a) -> (a, a) -> Complex a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Complex a
forall a. a -> a -> Complex a
(:+) ((a, a) -> Complex a) -> m (a, a) -> m (Complex a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector (a, a) -> Int -> m (a, a)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
G.basicUnsafeIndexM Vector (a, a)
v Int
i
  basicUnsafeCopy :: Mutable Vector (PrimState m) (Complex a)
-> Vector (Complex a) -> m ()
basicUnsafeCopy (MV_Complex mv) (V_Complex v)
                = Mutable Vector (PrimState m) (a, a) -> Vector (a, a) -> m ()
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> v a -> m ()
G.basicUnsafeCopy Mutable Vector (PrimState m) (a, a)
MVector (PrimState m) (a, a)
mv Vector (a, a)
v
  elemseq :: Vector (Complex a) -> Complex a -> b -> b
elemseq Vector (Complex a)
_ (a
x :+ a
y) b
z = Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (forall a. Vector a
forall a. HasCallStack => a
undefined :: Vector a) a
x
                       (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (forall a. Vector a
forall a. HasCallStack => a
undefined :: Vector a) a
y b
z

-- -------
-- Identity
-- -------
#define newtypeMVector(inst_ctxt,inst_head,tyC,con) \
instance inst_ctxt => M.MVector MVector (inst_head) where { \
; {-# INLINE basicLength          #-}                                         \
; {-# INLINE basicUnsafeSlice     #-}                                         \
; {-# INLINE basicOverlaps        #-}                                         \
; {-# INLINE basicUnsafeNew       #-}                                         \
; {-# INLINE basicInitialize      #-}                                         \
; {-# INLINE basicUnsafeReplicate #-}                                         \
; {-# INLINE basicUnsafeRead      #-}                                         \
; {-# INLINE basicUnsafeWrite     #-}                                         \
; {-# INLINE basicClear           #-}                                         \
; {-# INLINE basicSet             #-}                                         \
; {-# INLINE basicUnsafeCopy      #-}                                         \
; {-# INLINE basicUnsafeGrow      #-}                                         \
; basicLength (con v)                = M.basicLength v                        \
; basicUnsafeSlice i n (con v)       = con $ M.basicUnsafeSlice i n v         \
; basicOverlaps (con v1) (con v2)    = M.basicOverlaps v1 v2                  \
; basicUnsafeNew n                   = con `liftM` M.basicUnsafeNew n         \
; basicInitialize (con v)            = M.basicInitialize v                    \
; basicUnsafeReplicate n (tyC x)     = con `liftM` M.basicUnsafeReplicate n x \
; basicUnsafeRead (con v) i          = tyC `liftM` M.basicUnsafeRead v i      \
; basicUnsafeWrite (con v) i (tyC x) = M.basicUnsafeWrite v i x               \
; basicClear (con v)                 = M.basicClear v                         \
; basicSet (con v) (tyC x)           = M.basicSet v x                         \
; basicUnsafeCopy (con v1) (con v2)  = M.basicUnsafeCopy v1 v2                \
; basicUnsafeMove (con v1) (con v2)  = M.basicUnsafeMove v1 v2                \
; basicUnsafeGrow (con v) n          = con `liftM` M.basicUnsafeGrow v n      \
}
#define newtypeVector(inst_ctxt,inst_head,tyC,con,mcon) \
instance inst_ctxt => G.Vector Vector (inst_head) where { \
; {-# INLINE basicUnsafeFreeze  #-}                                       \
; {-# INLINE basicUnsafeThaw    #-}                                       \
; {-# INLINE basicLength        #-}                                       \
; {-# INLINE basicUnsafeSlice   #-}                                       \
; {-# INLINE basicUnsafeIndexM  #-}                                       \
; {-# INLINE elemseq            #-}                                       \
; basicUnsafeFreeze (mcon v)        = con `liftM` G.basicUnsafeFreeze v   \
; basicUnsafeThaw (con v)           = mcon `liftM` G.basicUnsafeThaw v    \
; basicLength (con v)               = G.basicLength v                     \
; basicUnsafeSlice i n (con v)      = con $ G.basicUnsafeSlice i n v      \
; basicUnsafeIndexM (con v) i       = tyC `liftM` G.basicUnsafeIndexM v i \
; basicUnsafeCopy (mcon mv) (con v) = G.basicUnsafeCopy mv v              \
; elemseq _ (tyC a)                 = G.elemseq (undefined :: Vector a) a \
}
#define deriveNewtypeInstances(inst_ctxt,inst_head,rep,tyC,con,mcon) \
newtype instance MVector s (inst_head) = mcon (MVector s (rep)) ;\
newtype instance Vector    (inst_head) = con  (Vector (rep))    ;\
instance inst_ctxt => Unbox (inst_head)                         ;\
newtypeMVector(inst_ctxt, inst_head, tyC, mcon)                 ;\
newtypeVector(inst_ctxt,  inst_head, tyC, con, mcon)

#if MIN_VERSION_base(4,8,0)
deriveNewtypeInstances(Unbox a, Identity a, a, Identity, V_Identity, MV_Identity)
#endif

deriveNewtypeInstances(Unbox a, Down a,    a, Down,    V_Down,    MV_Down)
deriveNewtypeInstances(Unbox a, Dual a,    a, Dual,    V_Dual,    MV_Dual)
deriveNewtypeInstances(Unbox a, Sum a,     a, Sum,     V_Sum,     MV_Sum)
deriveNewtypeInstances(Unbox a, Product a, a, Product, V_Product, MV_Product)


-- --------------
-- Data.Semigroup
-- --------------

#if MIN_VERSION_base(4,9,0)
deriveNewtypeInstances(Unbox a, Min a,   a, Min,   V_Min,   MV_Min)
deriveNewtypeInstances(Unbox a, Max a,   a, Max,   V_Max,   MV_Max)
deriveNewtypeInstances(Unbox a, First a, a, First, V_First, MV_First)
deriveNewtypeInstances(Unbox a, Last a,  a, Last,  V_Last,  MV_Last)
deriveNewtypeInstances(Unbox a, WrappedMonoid a, a, WrapMonoid, V_WrappedMonoid, MV_WrappedMonoid)

-- ------------------
-- Data.Semigroup.Arg
-- ------------------

newtype instance MVector s (Arg a b) = MV_Arg (MVector s (a,b))
newtype instance Vector    (Arg a b) = V_Arg  (Vector    (a,b))

instance (Unbox a, Unbox b) => Unbox (Arg a b)

instance (Unbox a, Unbox b) => M.MVector MVector (Arg a b) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: MVector s (Arg a b) -> Int
basicLength (MV_Arg v)                  = MVector s (a, b) -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength MVector s (a, b)
v
  basicUnsafeSlice :: Int -> Int -> MVector s (Arg a b) -> MVector s (Arg a b)
basicUnsafeSlice Int
i Int
n (MV_Arg v)         = MVector s (a, b) -> MVector s (Arg a b)
forall s a b. MVector s (a, b) -> MVector s (Arg a b)
MV_Arg (MVector s (a, b) -> MVector s (Arg a b))
-> MVector s (a, b) -> MVector s (Arg a b)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> MVector s (a, b) -> MVector s (a, b)
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice Int
i Int
n MVector s (a, b)
v
  basicOverlaps :: MVector s (Arg a b) -> MVector s (Arg a b) -> Bool
basicOverlaps (MV_Arg v1) (MV_Arg v2)   = MVector s (a, b) -> MVector s (a, b) -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps MVector s (a, b)
v1 MVector s (a, b)
v2
  basicUnsafeNew :: Int -> m (MVector (PrimState m) (Arg a b))
basicUnsafeNew Int
n                        = MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b)
forall s a b. MVector s (a, b) -> MVector s (Arg a b)
MV_Arg (MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b))
-> m (MVector (PrimState m) (a, b))
-> m (MVector (PrimState m) (Arg a b))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> m (MVector (PrimState m) (a, b))
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> m (v (PrimState m) a)
M.basicUnsafeNew Int
n
  basicInitialize :: MVector (PrimState m) (Arg a b) -> m ()
basicInitialize (MV_Arg v)              = MVector (PrimState m) (a, b) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicInitialize MVector (PrimState m) (a, b)
v
  basicUnsafeReplicate :: Int -> Arg a b -> m (MVector (PrimState m) (Arg a b))
basicUnsafeReplicate Int
n (Arg a
x b
y)        = MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b)
forall s a b. MVector s (a, b) -> MVector s (Arg a b)
MV_Arg (MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b))
-> m (MVector (PrimState m) (a, b))
-> m (MVector (PrimState m) (Arg a b))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> (a, b) -> m (MVector (PrimState m) (a, b))
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> a -> m (v (PrimState m) a)
M.basicUnsafeReplicate Int
n (a
x,b
y)
  basicUnsafeRead :: MVector (PrimState m) (Arg a b) -> Int -> m (Arg a b)
basicUnsafeRead (MV_Arg v) Int
i            = (a -> b -> Arg a b) -> (a, b) -> Arg a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Arg a b
forall a b. a -> b -> Arg a b
Arg ((a, b) -> Arg a b) -> m (a, b) -> m (Arg a b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector (PrimState m) (a, b) -> Int -> m (a, b)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
M.basicUnsafeRead MVector (PrimState m) (a, b)
v Int
i
  basicUnsafeWrite :: MVector (PrimState m) (Arg a b) -> Int -> Arg a b -> m ()
basicUnsafeWrite (MV_Arg v) Int
i (Arg a
x b
y) = MVector (PrimState m) (a, b) -> Int -> (a, b) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
M.basicUnsafeWrite MVector (PrimState m) (a, b)
v Int
i (a
x,b
y)
  basicClear :: MVector (PrimState m) (Arg a b) -> m ()
basicClear (MV_Arg v)                   = MVector (PrimState m) (a, b) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicClear MVector (PrimState m) (a, b)
v
  basicSet :: MVector (PrimState m) (Arg a b) -> Arg a b -> m ()
basicSet (MV_Arg v) (Arg a
x b
y)           = MVector (PrimState m) (a, b) -> (a, b) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> a -> m ()
M.basicSet MVector (PrimState m) (a, b)
v (a
x,b
y)
  basicUnsafeCopy :: MVector (PrimState m) (Arg a b)
-> MVector (PrimState m) (Arg a b) -> m ()
basicUnsafeCopy (MV_Arg v1) (MV_Arg v2) = MVector (PrimState m) (a, b)
-> MVector (PrimState m) (a, b) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
M.basicUnsafeCopy MVector (PrimState m) (a, b)
v1 MVector (PrimState m) (a, b)
v2
  basicUnsafeMove :: MVector (PrimState m) (Arg a b)
-> MVector (PrimState m) (Arg a b) -> m ()
basicUnsafeMove (MV_Arg v1) (MV_Arg v2) = MVector (PrimState m) (a, b)
-> MVector (PrimState m) (a, b) -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
M.basicUnsafeMove MVector (PrimState m) (a, b)
v1 MVector (PrimState m) (a, b)
v2
  basicUnsafeGrow :: MVector (PrimState m) (Arg a b)
-> Int -> m (MVector (PrimState m) (Arg a b))
basicUnsafeGrow (MV_Arg v) Int
n            = MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b)
forall s a b. MVector s (a, b) -> MVector s (Arg a b)
MV_Arg (MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b))
-> m (MVector (PrimState m) (a, b))
-> m (MVector (PrimState m) (Arg a b))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector (PrimState m) (a, b)
-> Int -> m (MVector (PrimState m) (a, b))
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
M.basicUnsafeGrow MVector (PrimState m) (a, b)
v Int
n

instance (Unbox a, Unbox b) => G.Vector Vector (Arg a b) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeFreeze :: Mutable Vector (PrimState m) (Arg a b) -> m (Vector (Arg a b))
basicUnsafeFreeze (MV_Arg v)   = Vector (a, b) -> Vector (Arg a b)
forall a b. Vector (a, b) -> Vector (Arg a b)
V_Arg (Vector (a, b) -> Vector (Arg a b))
-> m (Vector (a, b)) -> m (Vector (Arg a b))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Mutable Vector (PrimState m) (a, b) -> m (Vector (a, b))
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> m (v a)
G.basicUnsafeFreeze Mutable Vector (PrimState m) (a, b)
MVector (PrimState m) (a, b)
v
  basicUnsafeThaw :: Vector (Arg a b) -> m (Mutable Vector (PrimState m) (Arg a b))
basicUnsafeThaw (V_Arg v)      = MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b)
forall s a b. MVector s (a, b) -> MVector s (Arg a b)
MV_Arg (MVector (PrimState m) (a, b) -> MVector (PrimState m) (Arg a b))
-> m (MVector (PrimState m) (a, b))
-> m (MVector (PrimState m) (Arg a b))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector (a, b) -> m (Mutable Vector (PrimState m) (a, b))
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
v a -> m (Mutable v (PrimState m) a)
G.basicUnsafeThaw Vector (a, b)
v
  basicLength :: Vector (Arg a b) -> Int
basicLength (V_Arg v)          = Vector (a, b) -> Int
forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength Vector (a, b)
v
  basicUnsafeSlice :: Int -> Int -> Vector (Arg a b) -> Vector (Arg a b)
basicUnsafeSlice Int
i Int
n (V_Arg v) = Vector (a, b) -> Vector (Arg a b)
forall a b. Vector (a, b) -> Vector (Arg a b)
V_Arg (Vector (a, b) -> Vector (Arg a b))
-> Vector (a, b) -> Vector (Arg a b)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Vector (a, b) -> Vector (a, b)
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice Int
i Int
n Vector (a, b)
v
  basicUnsafeIndexM :: Vector (Arg a b) -> Int -> m (Arg a b)
basicUnsafeIndexM (V_Arg v) Int
i  = (a -> b -> Arg a b) -> (a, b) -> Arg a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Arg a b
forall a b. a -> b -> Arg a b
Arg ((a, b) -> Arg a b) -> m (a, b) -> m (Arg a b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector (a, b) -> Int -> m (a, b)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
G.basicUnsafeIndexM Vector (a, b)
v Int
i
  basicUnsafeCopy :: Mutable Vector (PrimState m) (Arg a b) -> Vector (Arg a b) -> m ()
basicUnsafeCopy (MV_Arg mv) (V_Arg v)
                                 = Mutable Vector (PrimState m) (a, b) -> Vector (a, b) -> m ()
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> v a -> m ()
G.basicUnsafeCopy Mutable Vector (PrimState m) (a, b)
MVector (PrimState m) (a, b)
mv Vector (a, b)
v
  elemseq :: Vector (Arg a b) -> Arg a b -> b -> b
elemseq Vector (Arg a b)
_ (Arg a
x b
y) b
z          = Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (forall a. Vector a
forall a. HasCallStack => a
undefined :: Vector a) a
x
                                 (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Vector b -> b -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (forall a. Vector a
forall a. HasCallStack => a
undefined :: Vector b) b
y b
z
#endif

deriveNewtypeInstances((), Any, Bool, Any, V_Any, MV_Any)
deriveNewtypeInstances((), All, Bool, All, V_All, MV_All)

-- -------
-- Const
-- -------

deriveNewtypeInstances(Unbox a, Const a b, a, Const, V_Const, MV_Const)

-- ---
-- Alt
-- ---

#if MIN_VERSION_base(4,8,0)
deriveNewtypeInstances(Unbox (f a), Alt f a, f a, Alt, V_Alt, MV_Alt)
#endif

-- -------
-- Compose
-- -------

#if MIN_VERSION_base(4,9,0)
deriveNewtypeInstances(Unbox (f (g a)), Compose f g a, f (g a), Compose, V_Compose, MV_Compose)
#endif

-- ------
-- Tuples
-- ------

#define DEFINE_INSTANCES
#include "unbox-tuple-instances"