Haskell - error by execution
I try to write a this 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)
开发者_Go百科But, now when i will use this monad and try to write return or >>= in code I get by compilation the warnings:
No explicit method nor default method for Prelude.return in the instance declaration. No explicit method nor default method for Prelude.>>= in the instance declaration.
Does anyone know how to fix this warnings?
thank you very much
Assuming that the layout of the code is exactly as displayed in your question, the problem is that your return
and >>=
definitions are not indented, so they are being defined as new top-level functions unrelated to the Monad class. Indent them and it should work.
精彩评论