vectorTH function updated so that it works in Clash
[matthijs/master-project/support/tfvec.git] / Data / Param / TFVec.hs
index 87838930a20542d6d5d5682df6a26b8ec525dd71..2357c21a9087bd94a0143b960c1e34e25d2b3e81 100644 (file)
@@ -50,7 +50,9 @@ module Data.Param.TFVec
   , concat
   , reverse
   , iterate
+  , iteraten
   , generate
+  , generaten
   , copy
   , copyn
   ) where
@@ -93,8 +95,11 @@ singleton x = x +> empty
 vectorCPS :: [a] -> (forall s . NaturalT s => TFVec s a -> w) -> w
 vectorCPS xs = unsafeVectorCPS (toInteger (P.length xs)) xs
 
+-- FIXME: Not the most elegant solution... but it works for now in clash
 vectorTH :: Lift a => [a] -> ExpQ
-vectorTH xs = (vectorCPS xs) lift
+-- vectorTH xs = (vectorCPS xs) lift
+vectorTH [] = [| empty |]
+vectorTH (x:xs) = [| x +> $(vectorTH xs) |]
 
 unsafeVector :: NaturalT s => s -> [a] -> TFVec s a
 unsafeVector l xs
@@ -228,17 +233,23 @@ concat = liftV (P.foldr ((P.++).unTFVec) [])
 reverse :: TFVec s a -> TFVec s a
 reverse = liftV P.reverse
 
-iterate :: NaturalT s => s -> (a -> a) -> a -> TFVec s a
-iterate s f x = let s' = fromIntegerT s in TFVec (P.take s' $ P.iterate f x)
+iterate :: NaturalT s => (a -> a) -> a -> TFVec s a
+iterate = iteraten (undefined :: s)
 
-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)
+iteraten :: NaturalT s => s -> (a -> a) -> a -> TFVec s a
+iteraten s f x = let s' = fromIntegerT s in TFVec (P.take s' $ P.iterate f x)
+
+generate :: NaturalT s => (a -> a) -> a -> TFVec s a
+generate = generaten (undefined :: s)
+
+generaten :: NaturalT s => s -> (a -> a) -> a -> TFVec s a
+generaten s f x = let s' = fromIntegerT s in TFVec (P.take s' $ P.tail $ P.iterate f 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
+copyn s x = iteraten s id x
 
 -- =============
 -- = Instances =