module Data.Vector.Fixed.Monomorphic (
DimMono
, Z
, S
, F.N1
, F.N2
, F.N3
, F.N4
, F.N5
, F.N6
, VectorMono(..)
, Arity
, Fun(..)
, length
, mk1
, mk2
, mk3
, mk4
, mk5
, replicate
, replicateM
, generate
, generateM
, unfoldr
, basis
, head
, tail
, reverse
, (!)
, eq
, map
, mapM
, mapM_
, imap
, imapM
, imapM_
, foldl
, foldr
, foldl1
, ifoldl
, ifoldr
, fold
, foldMap
, foldM
, ifoldM
, sum
, maximum
, minimum
, and
, or
, all
, any
, find
, zipWith
, zipWithM
, izipWith
, izipWithM
, convert
, toList
, fromList
) where
import Control.Monad (liftM)
import Data.Monoid (Monoid)
import qualified Data.Vector.Fixed as F
import Data.Vector.Fixed.Cont (S,Z,Arity,Fun(..))
import Prelude (Num,Eq,Ord,Functor(..),Monad(..),Int,Bool,(.),($),Maybe)
newtype Mono v a = Mono { getMono :: v }
type instance F.Dim (Mono v) = DimMono v
instance (VectorMono v, a ~ VectorElm v, Arity (DimMono v)) => F.Vector (Mono v) a where
construct = fmap Mono construct
inspect = inspect . getMono
basicIndex = basicIndex . getMono
type family DimMono v :: *
class Arity (DimMono v) => VectorMono v where
type VectorElm v :: *
construct :: Fun (DimMono v) (VectorElm v) v
inspect :: v -> Fun (DimMono v) (VectorElm v) r -> r
basicIndex :: v -> Int -> VectorElm v
basicIndex v i = Mono v F.! i
length :: Arity (DimMono v) => v -> Int
length = F.length . Mono
mk1 :: (VectorMono v, VectorElm v ~ a, DimMono v ~ F.N1)
=> a -> v
mk1 a1 = getMono $ F.mk1 a1
mk2 :: (VectorMono v, VectorElm v ~ a, DimMono v ~ F.N2)
=> a -> a-> v
mk2 a1 a2 = getMono $ F.mk2 a1 a2
mk3 :: (VectorMono v, VectorElm v ~ a, DimMono v ~ F.N3)
=> a -> a-> a -> v
mk3 a1 a2 a3 = getMono $ F.mk3 a1 a2 a3
mk4 :: (VectorMono v, VectorElm v ~ a, DimMono v ~ F.N4)
=> a -> a-> a -> a -> v
mk4 a1 a2 a3 a4 = getMono $ F.mk4 a1 a2 a3 a4
mk5 :: (VectorMono v, VectorElm v ~ a, DimMono v ~ F.N5)
=> a -> a-> a -> a -> a -> v
mk5 a1 a2 a3 a4 a5 = getMono $ F.mk5 a1 a2 a3 a4 a5
replicate :: (VectorMono v, VectorElm v ~ a) => a -> v
replicate = getMono . F.replicate
replicateM :: (VectorMono v, VectorElm v ~ a, Monad m) => m a -> m v
replicateM a = getMono `liftM` F.replicateM a
basis :: (VectorMono v, VectorElm v ~ a, Num a) => Int -> v
basis = getMono . F.basis
unfoldr :: (VectorMono v, VectorElm v ~ a) => (b -> (a,b)) -> b -> v
unfoldr f = getMono . F.unfoldr f
generate :: (VectorMono v, VectorElm v ~ a) => (Int -> a) -> v
generate = getMono . F.generate
generateM :: (Monad m, VectorMono v, VectorElm v ~ a) => (Int -> m a) -> m v
generateM f = getMono `liftM` F.generateM f
head :: (VectorMono v, VectorElm v ~ a, DimMono v ~ S n) => v -> a
head = F.head . Mono
tail :: ( VectorMono v, VectorElm v ~ a
, VectorMono w, VectorElm w ~ a
, DimMono v ~ S (DimMono w))
=> v -> w
tail v = getMono $ F.tail $ Mono v
reverse :: (VectorMono v) => v -> v
reverse = getMono . F.reverse . Mono
(!) :: (VectorMono v, VectorElm v ~ a) => v -> Int -> a
v ! n = Mono v F.! n
foldl :: (VectorMono v, VectorElm v ~ a)
=> (b -> a -> b) -> b -> v -> b
foldl f x = F.foldl f x . Mono
foldr :: (VectorMono v, VectorElm v ~ a)
=> (a -> b -> b) -> b -> v -> b
foldr f x = F.foldr f x . Mono
foldl1 :: (VectorMono v, VectorElm v ~ a, DimMono v ~ S n)
=> (a -> a -> a) -> v -> a
foldl1 f = F.foldl1 f . Mono
ifoldr :: (VectorMono v, VectorElm v ~ a)
=> (Int -> a -> b -> b) -> b -> v -> b
ifoldr f x = F.ifoldr f x . Mono
ifoldl :: (VectorMono v, VectorElm v ~ a)
=> (b -> Int -> a -> b) -> b -> v -> b
ifoldl f z = F.ifoldl f z . Mono
fold :: (VectorMono v, Monoid (VectorElm v)) => v -> VectorElm v
fold = F.fold . Mono
foldMap :: (VectorMono v, Monoid m) => (VectorElm v -> m) -> v -> m
foldMap f = F.foldMap f . Mono
foldM :: (VectorMono v, VectorElm v ~ a, Monad m)
=> (b -> a -> m b) -> b -> v -> m b
foldM f x = F.foldM f x . Mono
ifoldM :: (VectorMono v, VectorElm v ~ a, Monad m) => (b -> Int -> a -> m b) -> b -> v -> m b
ifoldM f x = F.ifoldM f x . Mono
sum :: (VectorMono v, VectorElm v ~ a, Num a) => v -> a
sum = F.sum . Mono
maximum :: (VectorMono v, VectorElm v ~ a, DimMono v ~ S n, Ord a) => v -> a
maximum = F.maximum . Mono
minimum :: (VectorMono v, VectorElm v ~ a, DimMono v ~ S n, Ord a) => v -> a
minimum = F.minimum . Mono
and :: (VectorMono v, VectorElm v ~ Bool) => v -> Bool
and = F.and . Mono
or :: (VectorMono v, VectorElm v ~ Bool) => v -> Bool
or = F.or . Mono
all :: (VectorMono v, VectorElm v ~ a) => (a -> Bool) -> v -> Bool
all f = F.all f . Mono
any :: (VectorMono v, VectorElm v ~ a) => (a -> Bool) -> v -> Bool
any f = F.any f . Mono
find :: (VectorMono v, VectorElm v ~ a) => (a -> Bool) -> v -> Maybe a
find f = F.find f . Mono
eq :: (VectorMono v, VectorElm v ~ a, Eq a) => v -> v -> Bool
eq v w = F.eq (Mono v) (Mono w)
map :: (VectorMono v, VectorElm v ~ a) => (a -> a) -> v -> v
map f = getMono . F.map f . Mono
mapM :: (VectorMono v, VectorElm v ~ a, Monad m)
=> (a -> m a) -> v -> m v
mapM f v = getMono `liftM` F.mapM f (Mono v)
mapM_ :: (VectorMono v, VectorElm v ~ a, Monad m) => (a -> m b) -> v -> m ()
mapM_ f = F.mapM_ f . Mono
imap :: (VectorMono v, VectorElm v ~ a) =>
(Int -> a -> a) -> v -> v
imap f = getMono . F.imap f . Mono
imapM :: (VectorMono v, VectorElm v ~ a, Monad m)
=> (Int -> a -> m a) -> v -> m v
imapM f v = getMono `liftM` F.imapM f (Mono v)
imapM_ :: (VectorMono v, VectorElm v ~ a, Monad m) => (Int -> a -> m b) -> v -> m ()
imapM_ f = F.imapM_ f . Mono
zipWith :: (VectorMono v, VectorElm v ~ a)
=> (a -> a -> a) -> v -> v -> v
zipWith f v u = getMono $ F.zipWith f (Mono v) (Mono u)
zipWithM :: (VectorMono v, VectorElm v ~ a, Monad m)
=> (a -> a -> m a) -> v -> v -> m v
zipWithM f v u = getMono `liftM` F.zipWithM f (Mono v) (Mono u)
izipWith :: (VectorMono v, VectorElm v ~ a)
=> (Int -> a -> a -> a) -> v -> v -> v
izipWith f v u = getMono $ F.izipWith f (Mono v) (Mono u)
izipWithM :: (VectorMono v, VectorElm v ~ a, Monad m)
=> (Int -> a -> a -> m a) -> v -> v -> m v
izipWithM f v u = getMono `liftM` F.izipWithM f (Mono v) (Mono u)
convert :: (VectorMono v, VectorMono w, VectorElm v ~ VectorElm w, DimMono v ~ DimMono w)
=> v -> w
convert = getMono . F.convert . Mono
toList :: (VectorMono v, VectorElm v ~ a) => v -> [a]
toList = foldr (:) []
fromList :: (VectorMono v, VectorElm v ~ a) => [a] -> v
fromList = getMono . F.fromList