Skip to content
GitLab
Menu
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
e7149e9b
Commit
e7149e9b
authored
Jan 11, 2018
by
Michael Hanus
Browse files
sequence renamed according to Haskell
parent
8dcd4672
Changes
1
Hide whitespace changes
Inline
Side-by-side
Prelude.curry
View file @
e7149e9b
...
...
@@ -44,7 +44,7 @@ module Prelude
, PEVAL
, Monad(..)
, Functor(..)
, sequence
M
, sequence
M
_, mapM, mapM_, foldM, liftM, forM, forM_
, sequence, sequence_, mapM, mapM_, foldM, liftM,
liftM2,
forM, forM_
, unlessM, whenM
#ifdef __PAKCS__
, (=:<<=), letrec
...
...
@@ -1812,25 +1812,22 @@ instance Monad [] where
-- 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)
sequence :: Monad m => [m a] -> m [a]
sequence = foldr (\m n -> m >>= \x -> n >>= \xs -> return (x:xs)) (return [])
--- Evaluates a sequence of monadic actions and ignores the results.
sequence
M
_ :: Monad m => [m _] -> m ()
sequence
M
_ = foldr (>>) (return ())
sequence_ :: Monad m => [m _] -> m ()
sequence_ = 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 = sequence
M
. map f
mapM f = sequence . 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 = sequence
M
_ . map f
mapM_ f = sequence_ . map f
--- Folds a list of elements using a binary monadic action and a value
--- for the empty list.
...
...
@@ -1842,6 +1839,12 @@ foldM f z (x:xs) = f z x >>= \z' -> foldM f z' xs
liftM :: Monad m => (a -> b) -> m a -> m b
liftM f m = m >>= return . f
--- Apply a pure binary function to the result of two monadic actions.
liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 f m1 m2 = do x1 <- m1
x2 <- m2
return (f x1 x2)
--- Like `mapM`, but with flipped arguments.
---
--- This can be useful if the definition of the function is longer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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