I'm implementing a very simple poor mans concurrency structure with the following data type:
data C m a = Atomic (m (C m a)) | Done a
I'm creating an instance of monad for this:
instance Monad m => Monad (C m) where
(>>=) (Atomic m) f = Atomic $ (liftM (>>= f) m)
(>>=) (Done v) f = f v
return = Done
Q1. Am I right in saying Atomic $ (liftM (>>= f) m)
is creating a new Atomic
monad which contains the result of f
(* -> *
) applied to the value inside of m
?
Q2. Am I right in saying the superclass Monad m
is used here to enable the use of liftM
? If so, as this is an instance of the Monad
class, why can't this access liftM
directly?