X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FTraversable.hs;h=3d3ae70eff395b5e8d55f3785457434c791d2aa5;hb=b22112520b01c4906eebd0b6894d4bf2665c11e2;hp=969e720612591426a791baf6cc10ab7c6b511a3e;hpb=c7dc14cd5106c9e3c5d481a09b6e6241f662e99d;p=ghc-base.git diff --git a/Data/Traversable.hs b/Data/Traversable.hs index 969e720..3d3ae70 100644 --- a/Data/Traversable.hs +++ b/Data/Traversable.hs @@ -62,7 +62,7 @@ import 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 @@ -103,10 +103,11 @@ 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 @@ -171,6 +172,7 @@ mapAccumR f s t = runStateR (traverse (StateR . flip f) t) s -- | This function may be used as a value for `fmap` in a `Functor` instance. fmapDefault :: Traversable t => (a -> b) -> t a -> t b +{-# INLINE fmapDefault #-} fmapDefault f = getId . traverse (Id . f) -- | This function may be used as a value for `Data.Foldable.foldMap`