add an INLINE to the list version of traverse, to enable fusion
[ghc-base.git] / Data / Traversable.hs
index df10679..28fa761 100644 (file)
@@ -47,6 +47,8 @@ import Data.Monoid (Monoid)
 import GHC.Arr
 #elif defined(__HUGS__)
 import Hugs.Array
+#elif defined(__NHC__)
+import Array
 #endif
 
 -- | Functors representing data structures that can be traversed from
@@ -60,7 +62,7 @@ import Hugs.Array
 --
 -- a suitable instance would be
 --
--- > instance Traversable Tree
+-- > instance Traversable Tree where
 -- >    traverse f Empty = pure Empty
 -- >    traverse f (Leaf x) = Leaf <$> f x
 -- >    traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r
@@ -101,19 +103,18 @@ class (Functor t, Foldable t) => Traversable t where
 -- instances for Prelude types
 
 instance Traversable Maybe where
-        traverse f Nothing = pure Nothing
+        traverse _ Nothing = pure Nothing
         traverse f (Just x) = Just <$> f x
 
 instance Traversable [] where
+        {-# INLINE traverse #-} -- so that traverse can fuse
         traverse f = Prelude.foldr cons_f (pure [])
           where cons_f x ys = (:) <$> f x <*> ys
 
         mapM = Prelude.mapM
 
-#ifndef __NHC__
 instance Ix i => Traversable (Array i) where
-    traverse f arr = listArray (bounds arr) `fmap` traverse f (elems arr)
-#endif
+        traverse f arr = listArray (bounds arr) `fmap` traverse f (elems arr)
 
 -- general functions