Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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. Re:  Adapting code from an imperative loop (Vlatko Basic)
   2. Re:  Adapting code from an imperative loop (Matt Williams)


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

Message: 1
Date: Fri, 19 Jun 2015 10:04:30 +0200
From: Vlatko Basic <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Adapting code from an imperative loop
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150619/d49e3623/attachment-0001.html>

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

Message: 2
Date: Fri, 19 Jun 2015 09:52:42 +0000
From: Matt Williams <[email protected]>
To: [email protected],  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Subject: Re: [Haskell-beginners] Adapting code from an imperative loop
Message-ID:
        <caftvgqb8k1orytextav9ws+v+owgrzwom3jmzn9obfwgqo0...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dear All,

Thanks for your help with this.

I have got the simple version working but now need to use Map.fromListWith,
and am having syntax problems.

I found a related question on Stack overflow (here: http://
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
stackoverflow.com
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
/questions/15514486/
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
haskell-converting-a-list-
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
of-
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
a-b-key-
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
value-pairs-
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
with-
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
possibly-
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
repeated-key
<http://stackoverflow.com/questions/15514486/haskell-converting-a-list-of-a-b-key-value-pairs-with-possibly-repeated-key>
).

However, I'm having problems understanding the additional function. The
signature should be :
(a -> a -> a) -> [(k, a)] -> Map

And so I assume I need to supply a function whose signature is:

(a -> a -> a)

Is that correct?

Thanks,
Matt

On Fri, 19 Jun 2015 09:04 Vlatko Basic <[email protected]> wrote:

>  To learn, I'd suggest you implement it first with the recursion (a tip:
> use a "loop" function in where clause), and than with fold. Those are
> important features to understand in Haskell. Try to use the "higher-level"
> functions as little as possible until you grasp the basics (like fold
> syntax).
>
> If you just need any solution, fromListWith is fine.
>
> br,
> vlatko
>
>
>
>  -------- Original Message --------
> Subject: Re: [Haskell-beginners] Adapting code from an imperative loop
> From: Matt Williams <[email protected]>
> <[email protected]>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell <[email protected]>
> <[email protected]>
> Date: 19/06/15 09:05
>
>
>  I tried doing it as a fold (the pattern of accumulating a value, where
> the accumulated value was the resulting Map), but couldn't manage the
> syntax.
>
> Have now got it partially working with fromListWith.
>
> Thanks a lot,
> Matt
>
>  On Fri, 19 Jun 2015 07:18 Bob Ippolito <[email protected]> wrote:
>
>> On Friday, June 19, 2015, Matt Williams <[email protected]>
>> wrote:
>>
>>> Dear All,
>>>
>>> I have been wrestling with this for a while now.
>>>
>>> I have a list of data items, and want to be able to access them, in a
>>> Hash Map, via a short summary of their characteristics.
>>>
>>> In an imperative language this might look like:
>>>
>>> myMap = new map()
>>> for elem in myElems:
>>>     key = makeKey(elem)
>>>     myMap[key] = myMap[key] + elem
>>>
>>> I have been trying to do this in Haskell, but am stuck on how to hand
>>> the Map back to itself each time.
>>>
>>> I have a function :: elem -> [p,q] to make the key, but the Map.insert
>>> function has the following signature:
>>>
>>> insert :: (Hashable
>>> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-Hashable.html#t:Hashable>
>>>  k, Ord
>>> <https://hackage.haskell.org/packages/archive/base/4.2.0.2/doc/html/Data-Ord.html#t:Ord>
>>>  k)
>>> => k -> a -> HashMap
>>> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
>>>  k
>>> a -> HashMap
>>> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
>>>  k
>>> a
>>>
>>> My thought was that I needed to go through the list of the elems, and at
>>> each point add them to the Hash Map, handing the updated Map onto the next
>>> step - but this is what I cannot write.
>>>
>>
>>  This is typically done with fromListWith or a combination of foldl' and
>> insertWith or alter.
>>
>>  -bob
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing 
> [email protected]http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>  _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150619/f65f2e1d/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 84, Issue 31
*****************************************

Reply via email to