From: Christiaan Baaij Date: Wed, 1 Jul 2009 08:13:22 +0000 (+0200) Subject: Removed 'group' function, updated rotl and rotr to work for empty vectors X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Fsupport%2Ftfvec.git;a=commitdiff_plain;h=25576fe76b567e77c0778d2cbb0f952a5d5a50e0 Removed 'group' function, updated rotl and rotr to work for empty vectors --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eefec2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.hi +*.o +*.swp +dist diff --git a/Data/Param/TFVec.hs b/Data/Param/TFVec.hs index 50b2fda..8783893 100644 --- a/Data/Param/TFVec.hs +++ b/Data/Param/TFVec.hs @@ -35,7 +35,6 @@ module Data.Param.TFVec , take , drop , select --- , group , (<+) , (++) , map @@ -175,13 +174,6 @@ 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 - (<+) :: TFVec s a -> a -> TFVec (Succ s) a (<+) (TFVec xs) x = TFVec (xs P.++ [x]) @@ -217,11 +209,18 @@ shiftr :: (PositiveT s, NaturalT n, n ~ Pred s, s ~ Succ n) => TFVec s a -> a -> TFVec s a 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 - -rotr :: (PositiveT s, s ~ Succ (Pred s)) => TFVec s a -> TFVec s a -rotr xs = tail xs <+ head xs +rotl :: forall s a . NaturalT s => TFVec s a -> TFVec s a +rotl = liftV rotl' + where vlen = fromIntegerT (undefined :: s) + rotl' [] = [] + rotl' xs = let (i,[l]) = splitAt (vlen - 1) xs + in l : i + +rotr :: NaturalT s => TFVec s a -> TFVec s a +rotr = liftV rotr' + where + rotr' [] = [] + rotr' (x:xs) = xs P.++ [x] concat :: TFVec s1 (TFVec s2 a) -> TFVec (s1 :*: s2) a concat = liftV (P.foldr ((P.++).unTFVec) []) diff --git a/tfvec.cabal b/tfvec.cabal index 488e90e..ed0cc89 100644 --- a/tfvec.cabal +++ b/tfvec.cabal @@ -1,5 +1,5 @@ name: tfvec -version: 0.1.1 +version: 0.1.2 synopsis: Fixed sized vectors. description: Vectors with numerically parameterized size, using type-level numerals from 'tfp' library