Running a list of functions
Hi all, Maybe a stupid question. I have a list of functions [IO ()] and want to run those functions one after another. I did this runList :: [IO ()] -> IO () runList [] = return () runList (f:fs) = do f runList fs which works fine. However, I'm curious if there is a library function doing exactly this? -- Manfred
sequence_ :: Monad m => [m a] -> m () ____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com On Aug 20, 2011, at 1:42 PM, Manfred Lotz wrote:
Hi all, Maybe a stupid question.
I have a list of functions [IO ()] and want to run those functions one after another.
I did this
runList :: [IO ()] -> IO () runList [] = return () runList (f:fs) = do f runList fs
which works fine.
However, I'm curious if there is a library function doing exactly this?
-- Manfred
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
Hi. On 20 August 2011 19:36, Manfred Lotz <manfred.lotz@arcor.de> wrote:
On Sat, 20 Aug 2011 14:08:43 -0400 David Place <d@vidplace.com> wrote:
sequence_ :: Monad m => [m a] -> m ()
Thanks. I found sequence but I have to learn to add an underscore to a funtion in order to see if this could be it.
Actually in this case sequence and sequence_ are identical. You have IO for m, and () for a, so: sequence :: [IO ()] -> IO () sequence_ :: [IO ()] -> IO () Ozgur
I stand corrected. Sorry for the additional confusion. On 20 August 2011 20:31, Brandon Allbery <allbery.b@gmail.com> wrote:
On Sat, Aug 20, 2011 at 15:21, Ozgur Akgun <ozgurakgun@gmail.com> wrote:
sequence :: [IO ()] -> IO () sequence_ :: [IO ()] -> IO ()
sequence isn't ([IO ()] -> IO [()])?
-- Ozgur Akgun
Ozgur Akgun <ozgurakgun@gmail.com> wrote:
Actually in this case sequence and sequence_ are identical. You have IO for m, and () for a, so:
sequence :: [IO ()] -> IO () sequence_ :: [IO ()] -> IO ()
No, compare the type signatures: sequence :: [IO ()] -> IO [()] sequence_ :: [IO ()] -> IO () In the former case you will receive a list of as many values of type () as there are actions. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
participants (5)
-
Brandon Allbery -
David Place -
Ertugrul Soeylemez -
Manfred Lotz -
Ozgur Akgun