Difference between revisions of "Restrict type of monadic binding"
Jump to navigation
Jump to search
m |
(+essay tag; should be obvious, since it's in the proposals cat, but...) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{essay}} |
||
+ | |||
According to [[Do notation considered harmful#Safety]] |
According to [[Do notation considered harmful#Safety]] |
||
the type of the monadic binding combinator (>>) should be restricted to |
the type of the monadic binding combinator (>>) should be restricted to |
||
Line 5: | Line 7: | ||
</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]] |
Latest revision as of 13:37, 12 June 2009
- This page addresses an aspect of Haskell style, which is to some extent a matter of taste. Just pick what you find appropriate for you and ignore the rest.
According to Do notation considered harmful#Safety the type of the monadic binding combinator (>>) should be restricted to
(>>) :: m () -> m a -> m a
This way, you can omit _ <-
only if the monadic return value has type ()
.
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 ()