没有显式实现警告

3

我定义了一个名为 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 []'

我不知道为什么会出现这个警告。我看到可能与缩进有关,但我不知道问题出在哪里。


5
按照定义的缩进进行修改即可。 - ThreeFx
好像我是瞎了,因为我没看到错误。 - user12345678
2
在每个定义前面加上两个空格。 - ThreeFx
哦,是的...谢谢! - user12345678
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接