可穿越的定義

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 通勤。