可穿越的定义

class (Functor t, Foldable t) => Traversable t where
    {-# MINIMAL traverse | sequenceA #-}
    
    traverse::Applicative f => (a -> f b) -> t a -> f (t b)
    traverse f = sequenceA . fmap f
    
    sequenceA::Applicative f => t (f a) -> f (t a)
    sequenceA = traverse id
    
    mapM::Monad m => (a -> m b) -> t a -> m (t b)
    mapM = traverse
    
    sequence::Monad m => t (m a) -> m (t a)
    sequence = sequenceA

Traversable 结构 t 是元素 a有限容器 ,可以通过有效的访客操作进行操作。访问者函数 f::a -> f b 对结构的每个元素执行副作用,traverse 使用 Applicative 组成这些副作用。另一种看待它的方式是 sequenceATraversable 结构与 Applicatives 通勤。