我这样定义了一个类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 []'


我不知道为什么会出现此警告。我读到可能是……。缩进,但我不知道这可能是什么错误。

最佳答案

正如@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

关于haskell - 没有明确的实现警告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28125038/

10-11 22:34
查看更多