class Monad m where  
    return :: a -> m a  
  
    (>>=) :: m a -> (a -> m b) -> m b  
  
    (>>) :: m a -> m b -> m b  
    x >> y = x >>= \\_ -> y  
  
    fail :: String -> m a  
    fail msg = error msg

Maybe Monad

instance Monad Maybe where
	return x = Just x
	Nothing >>= f = Nothing
	Just x >>= f = f x
	fail _ = Nothing

Do notation

ghci> Just 9 >>= (\\x -> Just (x > 8))  
Just True

-- 동일한 표현식

marySue :: Maybe Bool  
marySue = do   
    x <- Just 9  
    Just (x > 8)
wopwop :: Maybe Char  
wopwop = do  
    (x:xs) <- Just ""  
    return x

ghci> wopwop  
Nothing

List Monad

instance Monad [] where  
    return x = [x]  
    xs >>= f = concat (map f xs)  
    fail _ = []