Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fredrik Wieczerkowski
curry-libs
Commits
e387cd48
Commit
e387cd48
authored
Jan 10, 2018
by
Michael Hanus
Browse files
sequenceM, sequenceM_, mapM, mapM_ added (preliminary)
parent
46eddda6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Prelude.curry
View file @
e387cd48
...
...
@@ -44,6 +44,7 @@ module Prelude
, PEVAL
, Monad(..)
, Functor(..)
, sequenceM, sequenceM_, mapM, mapM_
#ifdef __PAKCS__
, (=:<<=), letrec
#endif
...
...
@@ -1804,3 +1805,30 @@ instance Monad [] where
xs >>= f = [y | x <- xs, y <- f x]
return x = [x]
fail _ = []
----------------------------------------------------------------------------
-- Some further useful monad operations which might be later generalized
-- or moved into some other base module.
--- Evaluates a sequence of monadic actions and collects all results in a list.
sequenceM :: Monad m => [m a] -> m [a]
sequenceM [] = return []
sequenceM (c:cs) = do x <- c
xs <- sequenceM cs
return (x:xs)
--- Evaluates a sequence of monadic actions and ignores the results.
sequenceM_ :: Monad m => [m _] -> m ()
sequenceM_ = foldr (>>) (return ())
--- Maps a monadic action function on a list of elements.
--- The results of all monadic actions are collected in a list.
mapM :: Monad m => (a -> m b) -> [a] -> m [b]
mapM f = sequenceM . map f
--- Maps a monadic action function on a list of elements.
--- The results of all monadic actions are ignored.
mapM_ :: Monad m => (a -> m _) -> [a] -> m ()
mapM_ f = sequenceM_ . map f
----------------------------------------------------------------------------
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment