Seeking constructive criticism on monad implementation
I'm learning monads, this is my first working one (aside from the trivial monad). Feel free to criticize everything in it ruthlessly. I'm especially interested in "more idiomatic" and "more elegant" kind of responses. This monad counts the number of binds performed. data C a = C {value :: a, count :: Int} deriving (Show) instance Monad C where (>>=) (C x c) f = C (value $ f x) (c + 1) return x = C x 0 add :: (Num a) => a -> a -> C a add x y = return $ x + y -- Simpler way to do this? foldM is obviously something different. mysum [x] = return x mysum (x:xs) = mysum xs >>= add x Stylistically