我像这样定义了一个类Stack
class Stack stack where
push :: a -> stack a -> stack a
top :: MonadPlus m => stack a -> m (a,stack a)
empty :: stack a
isEmpty :: stack a -> Bool
但是当我实现方法时
instance Stack [] where
push b bs = b:bs
top [] = mzero
top (b:bs) = return(b,bs)
empty = []
isEmpty [] = True
isEmpty _ = False
我收到此警告:
Warning: No explicit implementation for
`Types.push', `Types.top', `Types.empty', and `Types.isEmpty'
In the instance declaration for `Stack []'
我不知道为什么会出现这个警告。我读到它可能是某事。有了压痕,但我不知道那可能是什么错误。
答案 0 :(得分:5)
正如@ThreeFx所提到的,缩进很重要。
您在问题中所写的内容相当于:
instance Stack [] where
-- no implementation here
-- ordinary functions:
push b bs = b:bs
top [] = mzero
top (b:bs) = return(b,bs)
empty = []
isEmpty [] = True
isEmpty _ = False