user12345678
user12345678

Reputation: 63

No explict implementation warning

I defined a class Stack like this

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

but when i implement the methods

instance Stack [] where
push b bs = b:bs
top [] = mzero
top (b:bs) = return(b,bs)
empty = []
isEmpty [] = True
isEmpty _ = False

i get this warning:

Warning: No explicit implementation for
  `Types.push', `Types.top', `Types.empty', and `Types.isEmpty'
In the instance declaration for `Stack []'

I have no idea why this warning is showing up. I read that it could be sth. with the indention but i dont have a clue what could be wrong about that.

Upvotes: 3

Views: 1864

Answers (1)

user2556165
user2556165

Reputation:

As @ThreeFx mentioned, indentation is important.

What you wrote in your question is equivalent to:

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

Upvotes: 7

Related Questions