首页 > 解决方案 > Traversable 概念的术语

问题描述

为什么我们将结构的翻转称为“序列”,为什么要谈论“遍历”和“遍历”?

我正在讨论这些概念的haskell中的实现......

class (Functor t, Foldable t) => Traversable t where
    {-# MINIMAL traverse | sequenceA #-}

    -- | Map each element of a structure to an action, evaluate these actions
    -- from left to right, and collect the results. For a version that ignores
    -- the results see 'Data.Foldable.traverse_'.
    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
    -- and collect the results. For a version that ignores the results
    -- see 'Data.Foldable.sequenceA_'.
    sequenceA :: Applicative f => t (f a) -> f (t a)
    sequenceA = traverse id

标签: haskellcategory-theorytraversable

解决方案


它是“排序”,而不是“a” “按特定顺序排列”,这里从左到右。而且是对sequence :: Monad m => [m a] -> m [a](注意旧版base)的概括,可能会让名字更明显。


推荐阅读