Split copy function in two, one that accepts a lenght param, and one that doesn't
[matthijs/master-project/support/tfvec.git] / Data / Param / TFVec.hs
index 673d69b3bb7370394c936e84022b56c0a25875d6..50b2fda258b44de6c285aeacae5889aeeddd5ab9 100644 (file)
@@ -35,7 +35,7 @@ module Data.Param.TFVec
   , take
   , drop
   , select
-  , group
+--  , group
   , (<+)
   , (++)
   , map
@@ -53,6 +53,7 @@ module Data.Param.TFVec
   , iterate
   , generate
   , copy
+  , copyn
   ) where
     
 
@@ -82,7 +83,6 @@ deriving instance (NaturalT s, Typeable s, Data s, Typeable a, Data a) => Data (
 empty :: TFVec D0 a
 empty = TFVec []
 
-{-# NOINLINE (+>) #-}
 (+>) :: a -> TFVec s a -> TFVec (Succ s) a
 x +> (TFVec xs) = TFVec (x:xs)
 
@@ -175,12 +175,12 @@ select f s n = liftV (select' f' s' n')
           | otherwise = []
         selectFirst0 _ 0 [] = []
 
-group :: PositiveT n => n -> TFVec s a -> TFVec (Div s n) (TFVec n a)
-group n = liftV (group' (fromIntegerT n))
-  where group' :: Int -> [a] -> [TFVec s a]
-        group' n xs = case splitAtM n xs of
-                        Nothing -> []
-                        Just (ls, rs) -> TFVec ls : group' n rs
+-- group :: PositiveT n => n -> TFVec s a -> TFVec (Div s n) (TFVec n a)
+-- group n = liftV (group' (fromIntegerT n))
+--   where group' :: Int -> [a] -> [TFVec s a]
+--         group' n xs = case splitAtM n xs of
+--                         Nothing -> []
+--                         Just (ls, rs) -> TFVec ls : group' n rs
 
 (<+) :: TFVec s a -> a -> TFVec (Succ s) a
 (<+) (TFVec xs) x = TFVec (xs P.++ [x])
@@ -220,9 +220,8 @@ shiftr xs x = tail xs <+ x
 rotl :: (PositiveT s, s ~ Succ (Pred s)) => TFVec s a -> TFVec s a
 rotl xs = last xs +> init xs
 
-class Rotr a where rotr :: a -> a
-instance Rotr (TFVec D0 a) where rotr xs = xs
-instance (PositiveT s, s ~ Succ (Pred s)) => Rotr (TFVec s a) where rotr xs = tail xs <+ head xs
+rotr :: (PositiveT s, s ~ Succ (Pred s)) => TFVec s a -> TFVec s a
+rotr xs = tail xs <+ head xs
 
 concat :: TFVec s1 (TFVec s2 a) -> TFVec (s1 :*: s2) a
 concat = liftV (P.foldr ((P.++).unTFVec) [])
@@ -236,8 +235,11 @@ iterate s f x = let s' = fromIntegerT s in TFVec (P.take s' $ P.iterate f x)
 generate :: NaturalT s => s -> (a -> a) -> a -> TFVec s a
 generate s f x = let s' = fromIntegerT s in TFVec (P.take s' $ P.tail $ P.iterate f x)
 
-copy :: NaturalT s => s -> a -> TFVec s a
-copy s x = iterate s id x
+copy :: NaturalT s => a -> TFVec s a
+copy x = copyn (undefined :: s) x
+
+copyn :: NaturalT s => s -> a -> TFVec s a
+copyn s x = iterate s id x
 
 -- =============
 -- = Instances =