@@ -13,17 +13,25 @@ import IO
13infixl 5 >>=
13infixl 5 >>=
15interface Applicative m => Monad (m : Type -> Type) where
15interface Applicative m => Monad (m : Type -> Type) where
16+ ||| Also called `bind`.
16 (>>=) : m a -> ((result : a) -> m b) -> m b
17 (>>=) : m a -> ((result : a) -> m b) -> m b
18−||| Also called `join` or mu
19+ ||| Also called `flatten` or mu
19−flatten : Monad m => m (m a) -> m a
20+ join : m (m a) -> m a
20−flatten a = a >>= id
21+
22+ -- default implementations
23+ (>>=) x f = join (f <$> x)
22||| For compatibility with Haskell. Note that monads are **not** free to
26||| For compatibility with Haskell. Note that monads are **not** free to
23||| define `return` and `pure` differently!
27||| define `return` and `pure` differently!
24return : Monad m => a -> m a
28return : Monad m => a -> m a
25return = pure
29return = pure
31+flatten : Monad m => m (m a) -> m a
33+%deprecate flatten "Please use `join`, which is the standard name."
27-- Annoyingly, these need to be here, so that we can use them in other
35-- Annoyingly, these need to be here, so that we can use them in other
28-- Prelude modules other than the top level.
36-- Prelude modules other than the top level.