Follow

It is probably a bad idea in ,
but still surprising: does not
complain about using "do" to define (>>=) itself.
It seams to cause and endless loop.

newtype BadIdea a = B a
        deriving Show

instance Functor BadIdea where
        fmap f (B a) = B (f a)

instance Applicative BadIdea where
        pure x = B x
        (B f) <*> B x = B (f x)

instance Monad BadIdea where
        return x = B x
        ma >>= f = do
                 a <- ma
                 f a
-- instead of
--        (B a) >>= f = f a

main = print
        (B 5 >>= (\x -> B (2*x)))

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.