Permalink
Browse files

specialize length and null on GHC >= 7.10 (close #138)

  • Loading branch information...
1 parent 8eee01c commit e6829eb9301f43d6ac832d40caa0cdb18fadbd0f @ekmett committed Oct 9, 2017
Showing with 32 additions and 1 deletion.
  1. +4 −0 src/Linear/Plucker.hs
  2. +4 −0 src/Linear/Quaternion.hs
  3. +4 −0 src/Linear/V0.hs
  4. +8 −1 src/Linear/V1.hs
  5. +4 −0 src/Linear/V2.hs
  6. +4 −0 src/Linear/V3.hs
  7. +4 −0 src/Linear/V4.hs
View
@@ -183,6 +183,10 @@ instance Foldable Plucker where
foldMap g (Plucker a b c d e f) =
g a `mappend` g b `mappend` g c `mappend` g d `mappend` g e `mappend` g f
{-# INLINE foldMap #-}
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = False
+ length _ = 6
+#endif
instance Traversable Plucker where
traverse g (Plucker a b c d e f) =
View
@@ -202,6 +202,10 @@ instance Foldable Quaternion where
{-# INLINE foldMap #-}
foldr f z (Quaternion e v) = f e (F.foldr f z v)
{-# INLINE foldr #-}
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = False
+ length _ = 4
+#endif
instance Traversable Quaternion where
traverse f (Quaternion e v) = Quaternion <$> f e <*> traverse f v
View
@@ -132,6 +132,10 @@ instance Functor V0 where
instance Foldable V0 where
foldMap _ V0 = mempty
{-# INLINE foldMap #-}
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = True
+ length _ = 0
+#endif
instance Traversable V0 where
traverse _ V0 = pure V0
View
@@ -108,7 +108,7 @@ import qualified Data.Vector.Unboxed.Base as U
--data V2 a = V2 !a !a deriving (Eq,Ord,Show,Read,Data,Typeable)
newtype V1 a = V1 a
deriving (Eq,Ord,Show,Read,Data,Typeable,
- Functor,Foldable,Traversable,
+ Functor,Traversable,
Epsilon,Storable,NFData
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
,Generic
@@ -118,6 +118,13 @@ newtype V1 a = V1 a
#endif
)
+instance Foldable V1 where
+ foldMap f (V1 a) = f a
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = False
+ length _ = 1
+#endif
+
#if __GLASGOW_HASKELL__ >= 707
instance Finite V1 where
type Size V1 = 1
View
@@ -129,6 +129,10 @@ instance Functor V2 where
instance Foldable V2 where
foldMap f (V2 a b) = f a `mappend` f b
{-# INLINE foldMap #-}
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = False
+ length _ = 2
+#endif
instance Traversable V2 where
traverse f (V2 a b) = V2 <$> f a <*> f b
View
@@ -113,6 +113,10 @@ instance Functor V3 where
instance Foldable V3 where
foldMap f (V3 a b c) = f a `mappend` f b `mappend` f c
{-# INLINE foldMap #-}
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = False
+ length _ = 3
+#endif
instance Traversable V3 where
traverse f (V3 a b c) = V3 <$> f a <*> f b <*> f c
View
@@ -120,6 +120,10 @@ instance Functor V4 where
instance Foldable V4 where
foldMap f (V4 a b c d) = f a `mappend` f b `mappend` f c `mappend` f d
{-# INLINE foldMap #-}
+#if __GLASGOW_HASKELL__ >= 710
+ null _ = False
+ length _ = 4
+#endif
instance Traversable V4 where
traverse f (V4 a b c d) = V4 <$> f a <*> f b <*> f c <*> f d

0 comments on commit e6829eb

Please sign in to comment.