@@ -13,11 +13,15 @@ import IO
1313infixl 5 >>=
1414
1515interface Applicative m => Monad (m : Type -> Type) where
16+ ||| Also called `bind`.
1617 (>>=) : m a -> ((result : a) -> m b) -> m b
1718
18−||| Also called `join` or mu
19−flatten : Monad m => m (m a) -> m a
20−flatten a = a >>= id
19+ ||| Also called `join` or mu
20+ flatten : m (m a) -> m a
21+
22+ -- default implementations
23+ (>>=) x f = flatten (f <$> x)
24+ flatten x = x >>= (\y => y)
2125
2226||| For compatibility with Haskell. Note that monads are **not** free to
2327||| define `return` and `pure` differently!