Haskell - 执行错误

时间:2011-04-12 13:28:15

标签: haskell warnings monads

我尝试写一个这个monad

data W x = W x [String]

instance Monad W where
return x = W x []
W a h1 >>= f = case f a of 
    W b h2 -> W b (h1++h2)

但是,现在当我将使用这个monad并尝试在代码中编写return或>> =时,我会通过编译获得警告:

  

实例声明中没有显式方法或Prelude.return的默认方法。   实例声明中没有明确的方法或Prelude。>> =的默认方法。

有谁知道如何修复此警告?

非常感谢

1 个答案:

答案 0 :(得分:6)

假设代码的布局与问题中显示的完全一致,问题是您的return>>=定义没有缩进,因此它们被定义为新的顶级函数与Monad班级无关。缩进它们,它应该工作。

相关问题