/* Stop >>= \a -> >>= \b insane! */
instance + (m a) | + a & Monad m
where
(+) ma mb = ma >>= \a -> mb >>= \b -> return $! a + b
instance - (m a) | - a & Monad m
where
(-) ma mb = ma >>= \a -> mb >>= \b -> return $! a - b
instance * (m a) | * a & Monad m
where
(*) ma mb = ma >>= \a -> mb >>= \b -> return $! a * b
instance / (m a) | / a & Monad m
where
(/) ma mb = ma >>= \a -> mb >>= \b -> return $! a / b
instance mod (m a) | mod a & Monad m
where
(mod) ma mb = ma >>= \a -> mb >>= \b -> return $! a mod b
instance rem (m a) | rem a & Monad m
where
(rem) ma mb = ma >>= \a -> mb >>= \b -> return $! a rem b
/* http://hpaste.org/10673 */
Thursday, September 25, 2008
Monadic Arithmetics
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment