1
のは、私が Haskellで任意の数のMonadをどのようにモナド化するのですか?
x :: Monad a => [a]
x = [item1, item2, item3, ...]
があるとしましょうそして私はこれらのために何をしたい:
zipf' x (y:z) = getZipList $ foldl (<*>) (x <$> y) z
しかし、残念ながら:
y f = f <$> item1 <*> item2 <*> item3 <*> item4 <*> ...
は、以前私がZipListsでそれを行うためにこれを試してみました返された:
<interactive>:94:36: error:
• Occurs check: cannot construct the infinite type: a1 ~ a -> a1
Expected type: ZipList a1 -> ZipList a -> ZipList a1
Actual type: ZipList (a -> a1) -> ZipList a -> ZipList a1
• In the first argument of ‘foldl’, namely ‘(<*>)’
In the second argument of ‘($)’, namely ‘foldl (<*>) (x <$> y) z’
In the expression: getZipList $ foldl (<*>) (x <$> y) z
• Relevant bindings include
z :: [ZipList a] (bound at <interactive>:94:12)
y :: ZipList a (bound at <interactive>:94:10)
x :: a -> a1 (bound at <interactive>:94:7)
zipf' :: (a -> a1) -> [ZipList a] -> [a1]
(bound at <interactive>:94:1)
は私に 'sequence'のように見えます –
@ n.m。そのコメントを回答にプロモートする必要があります。 –
これは実際には「シーケンス」ではありませんか?私たちは 'm [a]'を望んでいないので、おそらく 'foldM'のようなもので折りたたみたいと思っていますが、質問で与えられた型が不可能であるために伝えるのは難しいです。 – amalloy