1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE NoImplicitPrelude #-}
5 {-# LANGUAGE NoMonomorphismRestriction #-}
6 {-# LANGUAGE ScopedTypeVariables #-}
7 {-# LANGUAGE TypeFamilies #-}
10 module Data.Vector.Fixed.Boxed,
18 import qualified Algebra.Additive as Additive ( C )
19 import qualified Algebra.Ring as Ring ( C )
20 import Data.Vector.Fixed (
28 import Data.Vector.Fixed (
32 import Data.Vector.Fixed.Boxed (
38 import NumericPrelude hiding ( abs, length, foldl )
49 -- >>> import Data.Vector.Fixed (mk3)
50 -- >>> let v1 = mk3 1 2 3 :: Vec3 Int
56 (!?) :: (Vector v a) => v a -> Int -> Maybe a
58 | idx < 0 || idx >= length v1 = Nothing
59 | otherwise = Just $ v1 ! idx
62 -- | Remove an element of the given vector.
66 -- >>> import Data.Vector.Fixed (mk3)
67 -- >>> let b = mk3 1 2 3 :: Vec3 Int
68 -- >>> delete b 1 :: Vec2 Int
71 delete :: (Vector v a,
78 fromList (lhalf ++ rhalf')
80 (lhalf, rhalf) = splitAt idx (toList v1)
84 -- | We provide our own sum because sum relies on a Num instance
85 -- from the Prelude that we don't have.
89 -- >>> import Data.Vector.Fixed (mk3)
90 -- >>> let b = mk3 1 2 3 :: Vec3 Int
94 element_sum :: (Additive.C a, Ring.C a, Vector v a) => v a -> a
95 element_sum = foldl (+) (fromInteger 0)