给出以下Typeclassopedia练习:
--Implement join :: M (N (M (N a))) -> M (N a),
--given distrib :: N (M a) -> M (N a) and
--assuming M and N are instances of Monad.
distrib :: (Monad m, Monad n) => n (m a) => m (n a)
distrib = undefined
我收到以下编译时错误。
ghci> :l MonadTransformers.hs
[1 of 1] Compiling Main ( MonadTransformers.hs, interpreted )
MonadTransformers.hs:7:34:
Expected a constraint, but `n (m a)' has kind `*'
In the type signature for `distrib':
distrib :: (Monad m, Monad n) => n (m a) => m (n a)
Failed, modules loaded: none.
我该如何解决?
答案 0 :(得分:3)
那应该是
distrib :: (Monad m, Monad n) => n (m a) -> m (n a)
=>
介于约束和其他类型之间。
->
是函数的中缀类型构造函数。
例如
(+) :: Num a => a -> a -> a
----- \ / \
\ arguments result
constraint