traverse
を実行するために、Applicative
インターフェイスから正確に何が必要なのかを理解しようとしています。制約が厳格であるかのようにデフォルトの実装では使用されないので、私は立ち往生しています。 Haskellのタイプシステムは実際の要件を記述するには弱すぎるのでしょうか?Applicative、FoldableとTraversableの関係は何ですか?
-- | 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
おそらく関連する側の質問、なぜsequenceA_
はFoldable
で定義されていますか?
[Traversable typeclassの目的](https://stackoverflow.com/questions/45798242/the-purpose-of-the-traversable-typeclass)の可能な複製 – user2407038
2番目の質問は1番目とは全く関係がないようです。しかし答えは簡単です: 'Foldable'は' sequenceA_'を実装するのに十分強力です。 – user2407038