Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 588
user12345678 Avatar asked Jul 06 '26 14:07

user12345678


1 Answers

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

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!