vector-heterogenous 0.0.1 → 0.0.2
raw patch · 3 files changed
+51/−25 lines, 3 files
Files
- src/Data/Vector/Heterogenous.hs +25/−18
- src/Data/Vector/Heterogenous/HList.hs +25/−6
- vector-heterogenous.cabal +1/−1
src/Data/Vector/Heterogenous.hs view
@@ -17,6 +17,14 @@ module Data.Vector.Heterogenous ( HVector(..) , vec+ + -- * Construction helpers+ , ValidHVector(..)+ , toHList+-- , HListBuilder(..)+-- , Indexer (..)+ + -- * Modules , module Data.Vector.Heterogenous.HList , module Data.Vector.Heterogenous.Unsafe )@@ -60,6 +68,23 @@ vecwrite v i [] = return () vecwrite v i (x:xs) = (seq x $ VM.write v i x) >> vecwrite v (i-1) xs +-------------------------------------------------------------------------------+++class + ( Downcast (HList xs) box+ , HLength (HList xs)+ , HListBuilder (Indexer (HVector box xs)) (HList xs)+ ) => ValidHVector box xs++instance + ( Downcast (HList xs) box+ , HLength (HList xs)+ , HListBuilder (Indexer (HVector box xs)) (HList xs)+ ) => ValidHVector box xs++---------------------------------------+ data Indexer xs = Indexer !xs !Int toHList :: HListBuilder (Indexer (HVector box xs)) ys => HVector box xs -> ys@@ -79,14 +104,6 @@ buildHList (Indexer (HVector v) i) = (unsafeUnbox $ v V.! i):::(buildHList (Indexer (HVector v) (i-1) :: Indexer (HVector box xs))) -{-instance - ( Semigroup (HList xs)- , Downcast (HList xs) box- , HLength (HList xs)- , HListBuilder (Indexer (HVector box xs)) (HList xs)- ) => Semigroup (HVector box xs) where- v1 <> v2 = vec (undefined::box) $ (toHList v1)<>(toHList v2)-}- instance ( Monoid (HList xs) , Downcast (HList xs) box@@ -117,13 +134,3 @@ view hv _ = Indexer hv (V.length (getvec hv) -n-1) `view` (undefined::Empty (ToNat1 n)) where n = fromIntegral $ fromSing (sing :: Sing n)- -{-instance View (HVector box (xs)) (Sing n) (xs :! n) where- view (HVector v) _ = unsafeUnbox $ v V.! n- where- n = fromIntegral $ fromSing (sing :: Sing n) :: Int-}- --- instance (ConstraintBox box (xs :! n), SingI n) => View (HVector box (xs)) (Sing (n::Nat)) (xs :! n) where--- view (HVector v) _ = unsafeUnbox $ v V.! n--- where--- n = fromIntegral $ fromSing (sing :: Sing n)
src/Data/Vector/Heterogenous/HList.hs view
@@ -26,6 +26,15 @@ , AnyBox -- * Type functions+ + -- ** Type Lists+ , Distribute (..)+ , Replicate (..)+ , Map (..)+ , Reverse (..)+ , (:!) (..)+ + -- ** Type Nats , Nat1(..) , ToNat1 , FromNat1@@ -42,8 +51,8 @@ -- | The heterogenous list data HList :: [*] -> * where- HNil :: HList '[]- (:::) :: t -> HList ts -> HList (t ': ts)+ HNil :: HList '[]+ (:::) :: t -> HList ts -> HList (t ': ts) infixr 5 ::: @@ -51,11 +60,21 @@ show _ = "HNil" instance (Show x, Show (HList xs)) => Show (HList (x ': xs)) where show (x:::xs) = show x ++":::"++show xs++instance Eq (HList '[]) where+ xs==ys = True+instance (Eq x, Eq (HList xs)) => Eq (HList (x ': xs)) where+ (x:::xs)==(y:::ys) = (x==y)&&(xs==ys) --- instance Semigroup (HList '[]) where--- HNil <> HNil = HNil--- instance (Semigroup x, Semigroup (HList xs)) => Semigroup (HList (x ': xs)) where--- (x:::xs)<>(y:::ys) = (x<>y):::(xs<>ys)+instance Ord (HList '[]) where+ compare HNil HNil = EQ+instance (Ord x, Ord (HList xs)) => Ord (HList (x ': xs)) where+ compare (x:::xs) (y:::ys) = + case compare x y of+ EQ -> compare xs ys+ LT -> LT+ GT -> GT+ instance Monoid (HList '[]) where mempty = HNil
vector-heterogenous.cabal view
@@ -1,5 +1,5 @@ Name: vector-heterogenous-Version: 0.0.1+Version: 0.0.2 Synopsis: A type-safe library for vectors whose elements can be of any type, or any type satisfying some constraints Description: Category: Data, Data Structures