
Hi Marcin, Thanks for your response. Yes my intention to use 'do' was to implement it in so called 'imperative' style coding. So if I understand it correctly there is no other way to achieve it via 'do' w/o using the monad transformers? Thanks again Shishir

It depends on what are you trying to achieve. The ListT monad transformer is an overkill for your example, as you don't use the "non-determinism" feature of ListT (code written using it can use whole lists of values as if it was one value with multiple "versions", any action can return any number of results, which are then combined together, perhaps without even calculating all of them if they're not needed); if you just want to sequence actions, it's enough to use mapM, mapM_, sequence, sequence_, and other functions from Control.Monad. But if you have something more complicated in mind, it might be worth taking a look at ListT and other transformers to see if they can be of any use to you. Best regards, Marcin Mrotek

What you really want is "replicateM_". But to answer your original question, you could do something like:
import Control.Monad.List
main = runListT $ do
_ <- ListT $ pure [1,2,3,4]
liftIO $ putStrLn "Test"
(replicateM_ is way better though)
Tom
El May 1, 2015, a las 10:23, Marcin Mrotek
It depends on what are you trying to achieve. The ListT monad transformer is an overkill for your example, as you don't use the "non-determinism" feature of ListT (code written using it can use whole lists of values as if it was one value with multiple "versions", any action can return any number of results, which are then combined together, perhaps without even calculating all of them if they're not needed); if you just want to sequence actions, it's enough to use mapM, mapM_, sequence, sequence_, and other functions from Control.Monad. But if you have something more complicated in mind, it might be worth taking a look at ListT and other transformers to see if they can be of any use to you.
Best regards, Marcin Mrotek _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Ah, sorry, I forgot about replicateM_. Best regards, Marcin Mrotek

The reply I gave before might be more helpful if you consider the fact that
a >> b >> c
is equivalent to
do a
b
c
You can then use
forM_ [1..4] (\_ -> putStrLn "Test")
What this does is,
1. map (\_ -> putStrLn "Test") on [1..4]
2. Use sequence_ to combine those operations
The even shorter way is replicateM_ which works like replicate from
Data.List
On 2 May 2015 at 01:39, Marcin Mrotek
Ah, sorry, I forgot about replicateM_.
Best regards, Marcin Mrotek _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat
participants (4)
-
amindfv@gmail.com
-
Marcin Mrotek
-
Shishir Srivastava
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)