Aleksey Khudyakov avatar Aleksey Khudyakov committed 85a2f77 Merge

Merge pull request #3 from tel/dev-empty-vec

Add an `Empty` tuple vector like the `Only` vector.

Comments (0)

Files changed (3)

Data/Vector/Fixed.hs

     -- $construction
     -- ** Small dimensions
     -- $smallDim
+  , mk0
   , mk1
   , mk2
   , mk3
     -- * Data types
   , VecList(..)
   , Only(..)
+  , Empty(..)
     -- ** Tuple synonyms
   , Tuple2
   , Tuple3
   {-# INLINE construct #-}
   {-# INLINE inspect   #-}
 
+-- | Empty tuple.
+data Empty a = Empty deriving (Typeable, Data)
+
+instance Functor Empty where
+  fmap _ Empty = Empty
+instance F.Foldable Empty where
+  foldr = foldr
+instance T.Traversable Empty where
+  sequenceA Empty = pure Empty
+  traverse _ Empty = pure Empty
+
+type instance Dim Empty = Z
+
+instance Vector Empty a where
+  construct = Fun Empty
+  inspect _ (Fun b) = b
+  {-# INLINE construct #-}
+  {-# INLINE inspect   #-}
 
 type Tuple2 a = (a,a)
 type Tuple3 a = (a,a,a)

Data/Vector/Fixed/Cont.hs

     S
   , Z
     -- ** Synonyms for small numerals
+  , N0    
   , N1
   , N2
   , N3
   , cons
   , consV
   , snoc
+  , mk0
   , mk1
   , mk2
   , mk3
 -- | Successor of n
 data S n deriving Typeable
 
+type N0 = Z
 type N1 = S Z
 type N2 = S N1
 type N3 = S N2
 
 newtype T_basis n = T_basis Int
 
+mk0 :: ContVec N0 a
+mk0 = ContVec $ \(Fun a) -> a
+{-# INLINE mk0 #-}
 
 mk1 :: a -> ContVec N1 a
 mk1 a1 = ContVec $ \(Fun f) -> f a1

Data/Vector/Fixed/Internal.hs

 infixr 1 <|
 
 
+mk0 :: (Vector v a, Dim v ~ C.N0) => v a
+mk0 = vector $ C.empty
+{-# INLINE mk0 #-}
 
 mk1 :: (Vector v a, Dim v ~ C.N1) => a -> v a
 mk1 a1 = vector $ C.mk1 a1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.