use*_*678 2 warnings haskell compiler-warnings ghc
我像这样定义了一个类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
Run Code Online (Sandbox Code Playgroud)
但是当我实施这些方法时
instance Stack [] where
push b bs = b:bs
top [] = mzero
top (b:bs) = return(b,bs)
empty = []
isEmpty [] = True
isEmpty _ = False
Run Code Online (Sandbox Code Playgroud)
我收到这个警告:
Warning: No explicit implementation for
`Types.push', `Types.top', `Types.empty', and `Types.isEmpty'
In the instance declaration for `Stack []'
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会出现这个警告.我读到它可能是某事.有了压痕,但我不知道那可能是错的.
正如@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
Run Code Online (Sandbox Code Playgroud)