# Restrict type of monadic binding

### From HaskellWiki

(Difference between revisions)

m |
(types of other monadic functions) |
||

Line 5: | Line 5: | ||

</haskell> | </haskell> | ||

This way, you can omit <hask> _ <- </hask> only if the monadic return value has type <hask> () </hask>. | This way, you can omit <hask> _ <- </hask> only if the monadic return value has type <hask> () </hask>. | ||

+ | |||

+ | Types of some other monadic operations should be restricted, too. | ||

+ | <haskell> | ||

+ | mapM_ :: Monad m => (a -> m ()) -> [a] -> m () | ||

+ | replicateM_ :: Monad m => Int -> m () -> m () | ||

+ | sequence_ :: Monad m => [m ()] -> m () | ||

+ | zipWithM_ :: Monad m => (a -> b -> m ()) -> [a] -> [b] -> m () | ||

+ | </haskell> | ||

[[Category:Proposals]] | [[Category:Proposals]] |

## Revision as of 16:09, 9 November 2007

According to Do notation considered harmful#Safety the type of the monadic binding combinator (>>) should be restricted to

(>>) :: m () -> m a -> m a

_ <-

()

Types of some other monadic operations should be restricted, too.

mapM_ :: Monad m => (a -> m ()) -> [a] -> m () replicateM_ :: Monad m => Int -> m () -> m () sequence_ :: Monad m => [m ()] -> m () zipWithM_ :: Monad m => (a -> b -> m ()) -> [a] -> [b] -> m ()