@@ -1,53 +0,0 @@
1−{-# LANGUAGE BangPatterns #-}
2−{-# LANGUAGE DataKinds #-}
4−{-# LANGUAGE KindSignatures #-}
5−{-# LANGUAGE ScopedTypeVariables #-}
6−{-# LANGUAGE StandaloneDeriving #-}
7−{-# LANGUAGE TypeOperators #-}
8−{-# LANGUAGE TypeFamilies #-}
9−{-# LANGUAGE PolyKinds #-}
11−module Grenade.Core.Vector (
21−-- | A more specific Tagged type, ensuring that a list
22−-- is equal to the Nat value.
23−newtype Vector (n :: Nat) a = Vector [a]
25−instance Foldable (Vector n) where
26− foldr f b (Vector as) = foldr f b as
28−instance KnownNat n => Traversable (Vector n) where
29− traverse f (Vector as) = mkVector <$> traverse f as
31−instance Functor (Vector n) where
32− fmap f (Vector as) = Vector (fmap f as)
34−instance Show a => Show (Vector n a) where
35− showsPrec d = showsPrec d . vecToList
37−instance Eq a => Eq (Vector n a) where
38− (Vector as) == (Vector bs) = as == bs
40−mkVector :: forall n a. KnownNat n => [a] -> Vector n a
42− = let du = fromIntegral . natVal $ (undefined :: Proxy n)
46− else error $ "Error creating staticly sized Vector of length: " ++
47− show du ++ " list is of length:" ++ show la
49−vecToList :: Vector n a -> [a]
50−vecToList (Vector as) = as
52−vectorZip :: (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c
53−vectorZip f (Vector as) (Vector bs) = Vector (zipWith f as bs)