
Hello all, I found myselft writing this ugly piece of code silenceAll :: TI -> State (M.Map CH StringState,[DtzEvent]) TI silenceAll t = silence t 0 >> silence t 1 >> silence t 2 >> silence t 3 >> silence t 4 >> silence t 5 >> silence t 6 >> return t because I couldn't figure out how to map (silence t) over [0..6]. What is the standard way of doing this?

Hi Martin, mapM_ is what you are looking for. Please ask again if you don't manage to make it work for you. Cheers, Ozgur.

Le 31 mars 2014 18:07, "martin"
Hello all,
I found myselft writing this ugly piece of code
silenceAll :: TI -> State (M.Map CH StringState,[DtzEvent]) TI silenceAll t =
Cut
because I couldn't figure out how to map (silence t) over [0..6]. What is
the standard way of doing this As said, mapM_ is the standard way to do that . How could you have found this for yourself ? The recommended way would be to use hoogle to search for the type signature you wish : (Monad m) => (a -> m b) -> [a] -> m () mapM_ would be among the first results. -- Jedaï

Am 03/31/2014 10:42 PM, schrieb Chaddaï Fouché:
Le 31 mars 2014 18:07, "martin"
mailto:martin.drautzburg@web.de> a écrit : Hello all,
I found myselft writing this ugly piece of code
silenceAll :: TI -> State (M.Map CH StringState,[DtzEvent]) TI silenceAll t =
Cut
because I couldn't figure out how to map (silence t) over [0..6]. What is the standard way of doing this
As said, mapM_ is the standard way to do that . How could you have found this for yourself ? The recommended way would be to use hoogle to search for the type signature you wish : (Monad m) => (a -> m b) -> [a] -> m () mapM_ would be among the first results.
Thanks Ozgur and Chaddai, this works. Two more questions: (1) I had tried mapM, but this didn't work. I am having trouble to understand why the return type is m() and not m [a] (2) Hoogle is http://www.haskell.org/hoogle, right? I mean, it is a web thing, not something I use from the commandline?

On Mon, Mar 31, 2014, at 09:15 PM, martin wrote:
(1) I had tried mapM, but this didn't work. I am having trouble to understand why the return type is m() and not m [a]
mapM_ is like mapM, except that mapM_ ignores the result value. In other words, mapM_ is for when you only want the monadic effects. You could define it like this: mapM_ f xs = mapM f xs >> return () -Karl

Il 01/apr/2014 06:17 "martin"
(2) Hoogle is http://www.haskell.org/hoogle, right? I mean, it is a web
thing, not something I use from the commandline?
You can also install it locally (depending on your OS/distro you might find a pre-packaged version or install it through cabal-install) and use it in the shell or even from inside ghci if you create the appropriate bindings in your ghci config. -- Nadir
participants (5)
-
Chaddaï Fouché
-
Karl Voelker
-
martin
-
Nadir Sampaoli
-
Ozgur Akgun