module Data.Vector.Fixed (
Dim
, Z
, S
, C.N1
, C.N2
, C.N3
, C.N4
, C.N5
, C.N6
, Vector(..)
, VectorN
, Arity
, Fun(..)
, length
, mk1
, mk2
, mk3
, mk4
, mk5
, New
, vec
, con
, (|>)
, replicate
, replicateM
, generate
, generateM
, unfoldr
, basis
, head
, tail
, cons
, (!)
, eq
, map
, mapM
, mapM_
, imap
, imapM
, imapM_
, sequence
, sequence_
, sequenceA
, traverse
, foldl
, foldr
, foldl1
, ifoldl
, ifoldr
, foldM
, ifoldM
, sum
, maximum
, minimum
, and
, or
, all
, any
, zipWith
, zipWithM
, izipWith
, izipWithM
, convert
, toList
, fromList
, fromList'
, fromListM
, fromFoldable
, VecList(..)
, Only(..)
) where
import Control.Applicative (Applicative(..),(<$>))
import Data.Data (Typeable,Data)
import qualified Data.Foldable as F
import qualified Data.Traversable as T
import Data.Vector.Fixed.Internal.Arity
import Data.Vector.Fixed.Cont (Vector(..),VectorN,Dim,length)
import qualified Data.Vector.Fixed.Cont as C
import Data.Vector.Fixed.Internal
import qualified Prelude as P
import Prelude hiding ( replicate,map,zipWith,maximum,minimum,and,or,all,any
, foldl,foldr,foldl1,length,sum
, head,tail,mapM,mapM_,sequence,sequence_
)
data VecList n a where
Nil :: VecList Z a
Cons :: a -> VecList n a -> VecList (S n) a
deriving (Typeable)
type instance Dim (VecList n) = n
instance Arity n => Vector (VecList n) a where
construct = Fun $ accum
(\(T_List f) a -> T_List (f . Cons a))
(\(T_List f) -> f Nil)
(T_List id :: T_List a n n)
inspect v (Fun f) = apply step (Flip v) f
where
step :: Flip VecList a (S k) -> (a, Flip VecList a k)
step (Flip (Cons a xs)) = (a, Flip xs)
instance Arity n => VectorN VecList n a
newtype Flip f a n = Flip (f n a)
newtype T_List a n k = T_List (VecList k a -> VecList n a)
instance (Show a, Arity n) => Show (VecList n a) where
show = show . foldr (:) []
instance (Eq a, Arity n) => Eq (VecList n a) where
(==) = eq
instance Arity n => Functor (VecList n) where
fmap = map
instance Arity n => Applicative (VecList n) where
pure = replicate
(<*>) = zipWith ($)
instance Arity n => F.Foldable (VecList n) where
foldr = foldr
instance Arity n => T.Traversable (VecList n) where
sequenceA = sequenceA
traverse = traverse
newtype Only a = Only a
deriving (Show,Eq,Ord,Typeable,Data)
instance Functor Only where
fmap f (Only a) = Only (f a)
instance F.Foldable Only where
foldr = foldr
instance T.Traversable Only where
sequenceA (Only f) = Only <$> f
traverse f (Only a) = Only <$> f a
type instance Dim Only = S Z
instance Vector Only a where
construct = Fun Only
inspect (Only a) (Fun f) = f a