]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Linear/Vector.hs
src/Linear/Vector.hs: add a Vec0 type.
[numerical-analysis.git] / src / Linear / Vector.hs
index 9d43bfac3122e82824d6a6921b6b33d69ba821a2..c9307153cc65330b2e0ec8e4f5eeec85d933607b 100644 (file)
@@ -2,11 +2,13 @@
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE TypeFamilies #-}
 
 module Linear.Vector (
   module Data.Vector.Fixed.Boxed,
+  Vec0,
   Vec1,
   (!?),
   delete,
@@ -20,9 +22,10 @@ import Data.Vector.Fixed (
   N1,
   S,
   Vector(..),
+  Z,
   fromList,
   toList )
-import qualified Data.Vector.Fixed as V (
+import Data.Vector.Fixed (
   (!),
   foldl,
   length )
@@ -32,8 +35,9 @@ import Data.Vector.Fixed.Boxed (
   Vec3,
   Vec4,
   Vec5 )
-import NumericPrelude hiding ( abs )
+import NumericPrelude hiding ( abs, length, foldl )
 
+type Vec0 = Vec Z
 type Vec1 = Vec N1
 
 
@@ -51,8 +55,8 @@ type Vec1 = Vec N1
 --
 (!?) :: (Vector v a) => v a -> Int -> Maybe a
 (!?) v1 idx
-  | idx < 0 || idx >= V.length v1 = Nothing
-  | otherwise                     = Just $ v1 V.! idx
+  | idx < 0 || idx >= length v1 = Nothing
+  | otherwise                   = Just $ v1 ! idx
 
 
 -- | Remove an element of the given vector.
@@ -77,7 +81,7 @@ delete v1 idx =
     rhalf' = tail rhalf
 
 
--- | We provide our own sum because V.sum relies on a Num instance
+-- | We provide our own sum because sum relies on a Num instance
 --   from the Prelude that we don't have.
 --
 --   Examples:
@@ -88,4 +92,4 @@ delete v1 idx =
 --   6
 --
 element_sum :: (Additive.C a, Ring.C a, Vector v a) => v a -> a
-element_sum = V.foldl (+) (fromInteger 0)
+element_sum = foldl (+) (fromInteger 0)