nhc only: expose Foldable and Traversable instances of Array
[ghc-base.git] / Data / Traversable.hs
index 7ad3991..969e720 100644 (file)
@@ -43,6 +43,14 @@ import Control.Applicative
 import Data.Foldable (Foldable())
 import Data.Monoid (Monoid)
 
+#if defined(__GLASGOW_HASKELL__)
+import GHC.Arr
+#elif defined(__HUGS__)
+import Hugs.Array
+#elif defined(__NHC__)
+import Array
+#endif
+
 -- | Functors representing data structures that can be traversed from
 -- left to right.
 --
@@ -104,6 +112,9 @@ instance Traversable [] where
 
         mapM = Prelude.mapM
 
+instance Ix i => Traversable (Array i) where
+        traverse f arr = listArray (bounds arr) `fmap` traverse f (elems arr)
+
 -- general functions
 
 -- | 'for' is 'traverse' with its arguments flipped.