我有一些组成两个单子的函数:
comp :: Monad m => m a -> m b -> m b
还有两个这样的单子实例,其中 on 是“内部” an Mfunctor
,
ms :: Monad m => m String
ms = undefined
tma :: (Monad m, MFunctor t) => t m a
tma = undefined
现在,如果我尝试ms
使用tma
:
tmas = hoist (\ma -> comp ma ms) tma
我收到此错误:
Could not deduce (a ~ [Char])
from the context (Monad m, MFunctor t)
bound by the inferred type of
comp :: (Monad m, MFunctor t) => t m b
at Coroutine.hs:607:1-40
`a' is a rigid type variable bound by
a type expected by the context: m a -> m a at Coroutine.hs:607:8
Expected type: m a
Actual type: m String
其中指出a
inms
必须是任意类型:ms :: Monad m => m a
.
为什么会这样,有没有办法tma
用特定参数的单子组成。
我可以看到葫芦的签名是:
hoist :: (Monad m, MFunctor t) => (forall a. m a -> n a) -> t m b -> t n b
但无法想象如何forall
影响我正在尝试做的事情,如果它有任何影响的话。