1. Aleksey Khudyakov
  2. fixed-vector

Commits

Comments (0)

Files changed (2)

File Data/Vector/Fixed.hs Modified

View file
  • Ignore whitespace
  • Hide word diff
 
 -- | Create vector form list. List must have same length as the
 --   vector.
-fromList :: forall v a. (Vector v a) => [a] -> v a
+fromList :: (Vector v a) => [a] -> v a
 {-# INLINE fromList #-}
-fromList xs
-  | length r == P.length xs = convert r
-  | otherwise               = error "Data.Vector.Fixed.fromList: bad list length"
-  where
-   r = VecList xs :: VecList (Dim v) a
+fromList = C.vector . C.fromList

File Data/Vector/Fixed/Cont.hs Modified

View file
  • Ignore whitespace
  • Hide word diff
   , ContVec
     -- * Construction of ContVec
   , cvec
+  , fromList
   , replicate
   , replicateM
   , generate
 cvec = ContVecT . inspect
 {-# INLINE[1] cvec #-}
 
+fromList :: forall r m n a. Arity n => [a] -> ContVecT r m n a
+{-# INLINE fromList #-}
+fromList xs = ContVecT $ \(Fun fun) ->
+  apply step
+        (T_flist xs :: T_flist a n)
+        fun
+  where
+    step (T_flist []    ) = error "Data.Vector.Fixed.Cont.fromList: too few elements"
+    step (T_flist (a:as)) = (a, T_flist as)
+
+data T_flist a n = T_flist [a]
+
 
 -- | Execute monadic action for every element of vector.
 replicate :: forall r m n a. (Arity n)