untabify
[ghc-base.git] / Data / Traversable.hs
index 52c44ab..841e278 100644 (file)
 -- or qualify uses of these function names with an alias for this module.
 
 module Data.Traversable (
-       Traversable(..),
-       for,
-       forM,
-       fmapDefault,
-       foldMapDefault,
-       ) where
+        Traversable(..),
+        for,
+        forM,
+        fmapDefault,
+        foldMapDefault,
+        ) where
 
 import Prelude hiding (mapM, sequence, foldr)
 import qualified Prelude (mapM, foldr)
@@ -53,9 +53,9 @@ import Data.Monoid (Monoid)
 -- a suitable instance would be
 --
 -- > instance Traversable Tree
--- >   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
+-- >    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
 --
 -- This is suitable even for abstract types, as the laws for '<*>'
 -- imply a form of associativity.
@@ -70,37 +70,37 @@ import Data.Monoid (Monoid)
 --    ('foldMapDefault').
 --
 class (Functor t, Foldable t) => Traversable t where
-       -- | Map each element of a structure to an action, evaluate
-       -- these actions from left to right, and collect the results.
-       traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
-       traverse f = sequenceA . fmap f
-
-       -- | Evaluate each action in the structure from left to right,
-       -- and collect the results.
-       sequenceA :: Applicative f => t (f a) -> f (t a)
-       sequenceA = traverse id
-
-       -- | Map each element of a structure to a monadic action, evaluate
-       -- these actions from left to right, and collect the results.
-       mapM :: Monad m => (a -> m b) -> t a -> m (t b)
-       mapM f = unwrapMonad . traverse (WrapMonad . f)
-
-       -- | Evaluate each monadic action in the structure from left to right,
-       -- and collect the results.
-       sequence :: Monad m => t (m a) -> m (t a)
-       sequence = mapM id
+        -- | Map each element of a structure to an action, evaluate
+        -- these actions from left to right, and collect the results.
+        traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
+        traverse f = sequenceA . fmap f
+
+        -- | Evaluate each action in the structure from left to right,
+        -- and collect the results.
+        sequenceA :: Applicative f => t (f a) -> f (t a)
+        sequenceA = traverse id
+
+        -- | Map each element of a structure to a monadic action, evaluate
+        -- these actions from left to right, and collect the results.
+        mapM :: Monad m => (a -> m b) -> t a -> m (t b)
+        mapM f = unwrapMonad . traverse (WrapMonad . f)
+
+        -- | Evaluate each monadic action in the structure from left to right,
+        -- and collect the results.
+        sequence :: Monad m => t (m a) -> m (t a)
+        sequence = mapM id
 
 -- instances for Prelude types
 
 instance Traversable Maybe where
-       traverse f Nothing = pure Nothing
-       traverse f (Just x) = Just <$> f x
+        traverse f Nothing = pure Nothing
+        traverse f (Just x) = Just <$> f x
 
 instance Traversable [] where
-       traverse f = Prelude.foldr cons_f (pure [])
-         where cons_f x ys = (:) <$> f x <*> ys
+        traverse f = Prelude.foldr cons_f (pure [])
+          where cons_f x ys = (:) <$> f x <*> ys
 
-       mapM = Prelude.mapM
+        mapM = Prelude.mapM
 
 -- general functions
 
@@ -128,8 +128,8 @@ foldMapDefault f = getConst . traverse (Const . f)
 newtype Id a = Id { getId :: a }
 
 instance Functor Id where
-       fmap f (Id x) = Id (f x)
+        fmap f (Id x) = Id (f x)
 
 instance Applicative Id where
-       pure = Id
-       Id f <*> Id x = Id (f x)
+        pure = Id
+        Id f <*> Id x = Id (f x)