模棱两可的发生`Monad'

时间:2017-03-19 12:39:50

标签: haskell monads typeclass ambiguous

我目前正在使用Monad类型,这是我的代码:

class Monad m where  
    return :: a -> m a  

    (>>==) :: m a -> (a -> m b) -> m b  

    (>>) :: m a -> m b -> m b  
    x >> y = x >>== \_ -> y  

    fail :: String -> m a  
    fail msg = error msg  


instance Monad Maybe where  
    return x = Just x  
    Nothing >>= f = Nothing  
    Just x >>= f  = f x  
    fail _ = Nothing 

main = do
    print $ return "WHAT" :: Maybe String 
    print $ Just 9 >>= \x -> return (x*10)  
    print $ Nothing >>= \x -> return (x*10)  

我收到了此错误消息:

Ambiguous occurrence `Monad'
It could refer to either `Main.Monad'....or `Prelude.Monad',....

我尝试导入Prelude并隐藏Monad但是得到更新和更新的错误消息让我更加困惑,提前谢谢你,Tamas

0 个答案:

没有答案