Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Mapping inside State (martin)
   2. Re:  Mapping inside State (Ozgur Akgun)
   3. Re:  Mapping inside State (Chadda? Fouch?)
   4. Re:  Mapping inside State (martin)
   5. Re:  Mapping inside State (Karl Voelker)
   6. Re:  Mapping inside State (Nadir Sampaoli)


----------------------------------------------------------------------

Message: 1
Date: Mon, 31 Mar 2014 18:07:20 +0200
From: martin <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Mapping inside State
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15

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?


------------------------------

Message: 2
Date: Mon, 31 Mar 2014 17:25:51 +0100
From: Ozgur Akgun <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mapping inside State
Message-ID:
        <calzazpcvgsz9xqtw2ia_bkqbzwhfqdkeg1y49ah9t-b0yqt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140331/45731a3a/attachment-0001.html>

------------------------------

Message: 3
Date: Mon, 31 Mar 2014 22:42:06 +0200
From: Chadda? Fouch? <[email protected]>
To: beginners <[email protected]>
Subject: Re: [Haskell-beginners] Mapping inside State
Message-ID:
        <CANfjZRbtTWaEOTb=6A3u-fw=nhmsjr6a5sw8w0ql3owc97y...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Le 31 mars 2014 18:07, "martin" <[email protected]> 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.

-- 
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140331/b6add265/attachment-0001.html>

------------------------------

Message: 4
Date: Tue, 01 Apr 2014 06:15:58 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mapping inside State
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Am 03/31/2014 10:42 PM, schrieb Chadda? Fouch?:
> 
> Le 31 mars 2014 18:07, "martin" <[email protected] 
> <mailto:[email protected]>> 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?




------------------------------

Message: 5
Date: Mon, 31 Mar 2014 21:36:17 -0700
From: Karl Voelker <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Mapping inside State
Message-ID:
        <[email protected]>
Content-Type: text/plain

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


------------------------------

Message: 6
Date: Tue, 1 Apr 2014 07:31:39 +0200
From: Nadir Sampaoli <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mapping inside State
Message-ID:
        <cafywtdrhv3ccqpcrb3kgyxikbkbfxra5tjwyoz1caz35afr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Il 01/apr/2014 06:17 "martin" <[email protected]> ha scritto:
>
> (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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140401/ea338efb/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 70, Issue 1
****************************************

Reply via email to