class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
m >> n = m >>= \_ -> n
fail :: String -> m a
I’ve never seen a equation(or function declaration?) in typeclass before. Why is there a equation in typeclass?
I know _ is a term for matching anything. but what m >>= \_ -> n match?
It’s a default implementation for the method. Unless your instance declaration contains an explicit implementation of
(>>), that’s the definition that will be used. Default methods are widespread if some method can be implemented using another method, but potentially there can be more efficient implementations for some datatypes.means the ‘result’ of
mis fed to the function that ignores its argument and returnsnno matter. It could also be writtenIn the context of monads with effects, it’s ‘do
mto have the effects, but ignore the return value, then don‘. That’s what(>>)is meant to do there.