Commits

Aleksey Khudyakov committed 596ac2e

Move VecList to D.V.F.Cont

Comments (0)

Files changed (3)

Data/Vector/Fixed.hs

   ) where
 
 import Data.Vector.Fixed.Internal
+import Data.Vector.Fixed.Cont     (VecList(..))
 
 import qualified Prelude as P
 import Prelude hiding ( replicate,map,zipWith,maximum,minimum

Data/Vector/Fixed/Cont.hs

-{-# LANGUAGE TypeFamilies #-}
-{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FlexibleInstances     #-}
+{-# LANGUAGE TypeFamilies          #-}
+{-# LANGUAGE ScopedTypeVariables   #-}
 -- |
 -- Continuations-based API
 module Data.Vector.Fixed.Cont (
   , cvec
     -- * Running ContVec
   , vector
+    -- * Data types
+  , VecList(..) -- FIXME: unsafe
   ) where
 
 import Control.Applicative
 vector :: (Vector v a, Dim v ~ n) => ContVec (v a) n a -> v a
 vector c = runContVec c construct
 {-# INLINE vector #-}
+
+
+-- | Vector based on the lists. Not very useful by itself but is
+--   necessary for implementation.
+newtype VecList n a = VecList [a]
+                      deriving (Show,Eq)
+
+type instance Dim (VecList n) = n
+
+newtype Flip f a n = Flip (f n a)
+
+newtype T_list a n = T_list ([a] -> [a])
+
+-- It's vital to avoid 'reverse' and build list using [a]->[a]
+-- functions. Reverse is recursive and interferes with inlining.
+instance Arity n => Vector (VecList n) a where
+  construct = Fun $ accum
+    (\(T_list xs) x -> T_list (xs . (x:)))
+    (\(T_list xs) -> VecList (xs []) :: VecList n a)
+    (T_list id :: T_list a n)
+  inspect v (Fun f) = apply
+    (\(Flip (VecList (x:xs))) -> (x, Flip (VecList xs)))
+    (Flip v)
+    f
+  {-# INLINE construct #-}
+  {-# INLINE inspect   #-}
+instance Arity n => VectorN VecList n a

Data/Vector/Fixed/Internal.hs

   , VectorN
   , length
   , Id(..)
-    -- * Data types
-  , VecList(..) -- FIXME: unsafe
     -- * Deforestation
     -- $deforestation
   , Cont(..)
 instance RealFloat a => Vector Complex a where
   construct = Fun (:+)
   inspect (x :+ y) (Fun f) = f x y
-
-
-
--- | Vector based on the lists. Not very useful by itself but is
---   necessary for implementation.
-newtype VecList n a = VecList [a]
-                      deriving (Show,Eq)
-
-type instance Dim (VecList n) = n
-
-newtype Flip f a n = Flip (f n a)
-
-newtype T_list a n = T_list ([a] -> [a])
-
--- It's vital to avoid 'reverse' and build list using [a]->[a]
--- functions. Reverse is recursive and interferes with inlining.
-instance Arity n => Vector (VecList n) a where
-  construct = Fun $ accum
-    (\(T_list xs) x -> T_list (xs . (x:)))
-    (\(T_list xs) -> VecList (xs []) :: VecList n a)
-    (T_list id :: T_list a n)
-  inspect v (Fun f) = apply
-    (\(Flip (VecList (x:xs))) -> (x, Flip (VecList xs)))
-    (Flip v)
-    f
-  {-# INLINE construct #-}
-  {-# INLINE inspect   #-}
-instance Arity n => VectorN VecList n a