1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
5 {-# LANGUAGE TypeFamilies #-}
10 import Data.Vector.Fixed (
20 import qualified Data.Vector.Fixed as V (
23 import Data.Vector.Fixed.Boxed
34 -- >>> import Data.Vector.Fixed (mk2)
35 -- >>> let v1 = mk2 1 2 :: Vec2 Int
39 (!) :: (Vector v a) => v a -> Int -> a
40 (!) v1 idx = (toList v1) !! idx
46 -- >>> import Data.Vector.Fixed (mk3)
47 -- >>> let v1 = mk3 1 2 3 :: Vec3 Int
53 (!?) :: (Vector v a) => v a -> Int -> Maybe a
55 | idx < 0 || idx >= V.length v1 = Nothing
56 | otherwise = Just $ v1 ! idx
59 -- | Remove an element of the given vector.
63 -- >>> import Data.Vector.Fixed (mk3)
64 -- >>> let b = mk3 1 2 3 :: Vec3 Int
65 -- >>> delete b 1 :: Vec2 Int
68 delete :: (Vector v a, Vector w a, Dim v ~ S (Dim w)) => v a -> Int -> w a
70 fromList $ (lhalf ++ rhalf')
72 (lhalf, rhalf) = splitAt idx (toList v1)