[Haskell-beginners] Bound library questions

Anthony Lee anthonynlee at gmail.com
Fri Aug 17 10:46:52 UTC 2018


In Scope.hs there are some functions I feel difficult to understand,
Why fmap/foldmap/traverse is applied three times?

instance Functor f => Functor (Scope b f) where
fmap f (Scope a) = Scope (fmap (fmap (fmap f)) a)
{-# INLINE fmap #-}

-- | @'toList'@ is provides a list (with duplicates) of the free variables
instance Foldable f => Foldable (Scope b f) where
foldMap f (Scope a) = foldMap (foldMap (foldMap f)) a
{-# INLINE foldMap #-}

instance Traversable f => Traversable (Scope b f) where
traverse f (Scope a) = Scope <$> traverse (traverse (traverse f)) a
{-# INLINE traverse #-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180817/429114c8/attachment.html>


More information about the Beginners mailing list