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.  Printing the entries of a Data.Map m (Manfred Lotz)
   2. Re:  Multiple versions (Tom Murphy)
   3. Re:  Printing the entries of a Data.Map m (Matthias Guedemann)
   4. Re:  Printing the entries of a Data.Map m (Manfred Lotz)
   5. Re:  Printing the entries of a Data.Map m (Matthias Guedemann)


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

Message: 1
Date: Sun, 15 May 2011 09:32:32 +0200
From: Manfred Lotz <[email protected]>
Subject: [Haskell-beginners] Printing the entries of a Data.Map m
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Hi all,
I have a map with some two thousand entries. Now I want to print that
map.


I could do:
   print m


but I like to use my own print function:
   mapM_ myprint (Map.toList m)


I may be wrong but having to use Map.toList looks pretty inefficient.

Question: I'd like to know if there is a more efficient way to do it?



-- 
Manfred





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

Message: 2
Date: Sun, 15 May 2011 04:13:52 -0400
From: Tom Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Multiple versions
To: Mark Bestley <news{@bestley.co.uk>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

My god! Another ghci!

Thanks for helping me find that.

Re-running the Haskell Platform installer ends with an "Installation
Failed," and I know enough to not start swapping out binaries in
/opt/local/bin, so is there a best-practices way to fix this?

Thank you
Tom

On 5/15/11, Mark Bestley <news{@bestley.co.uk> wrote:
> Tom Murphy <[email protected]> wrote:
>
>> Hi all,
>> Despite my best efforts, there are multiple versions of the Haskell
>> Platform on my system.
>>
>> I'm running Mac OSX, 10.6. I've installed the newest Haskell Platform,
>> from its installer package.
>>
>>
>> In /Library/Frameworks/GHC.framework/Versions, there is only one
>> folder: the latest.
>> Previously, though, I had to delete by hand an older version of GHC in
>> the Versions folder.
>>
>> There are no Haskell or GHC folders in ~/Library.
>>
>> When I run the ghci that's in the
>> /Library/Frameworks/GHC.framework/Versions folder, it's the right
>> version. Yet when I type "ghci" in the prompt, it gives me "GHCi,
>> version 6.10.4"
>>
>>
>> Any help would be very appreciated!
>> Tom
>
> What does
> which ghci
> at the prompt show?
>
> this is the actual binary - Haskell platform puts this in /usr/bin
> (which is not good as this is reserved for Apple's code and so could be
> deleted by a OS upgrade)
>
>
> --
> Mark
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 3
Date: Sun, 15 May 2011 10:15:42 +0200
From: Matthias Guedemann <[email protected]>
Subject: Re: [Haskell-beginners] Printing the entries of a Data.Map m
To: "beginners\@haskell.org" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Hi Manfred,

> I may be wrong but having to use Map.toList looks pretty inefficient.
> 
> Question: I'd like to know if there is a more efficient way to do it?

I do not know if it is really more efficient (it has to consider each
entry, just like converting to list does), but Data.Map is an instance
of Data.Traversable, which has the traverse function, see:

http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.3.1.0/Data-Traversable.html#t:Traversable

e.g.

Prelude> :m Data.Map Data.Traversable 
Prelude Data.Map Data.Traversable> let mymap = insert 1 "bubu" $ insert 2 
"baba" $ empty
Prelude Data.Map Data.Traversable> traverse print mymap
"bubu"
"baba"
fromList [(1,()),(2,())]
Prelude Data.Map Data.Traversable> 


Is this what you meant? You probably want to ingnore the result value of
type 

Prelude Data.Map Data.Traversable> :t (traverse print mymap)
(traverse print mymap) :: (Num t, Ord t) => IO (Map t ())


regards
Matthias



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

Message: 4
Date: Sun, 15 May 2011 10:51:19 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] Printing the entries of a Data.Map m
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Hi Matthias,

On Sun, 15 May 2011 10:15:42 +0200
Matthias Guedemann <[email protected]> wrote:

> 
> Hi Manfred,
> 
> > I may be wrong but having to use Map.toList looks pretty
> > inefficient.
> > 
> > Question: I'd like to know if there is a more efficient way to do
> > it?
> 
> I do not know if it is really more efficient (it has to consider each
> entry, just like converting to list does), but Data.Map is an instance
> of Data.Traversable, which has the traverse function, see:
> 
> http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.3.1.0/Data-Traversable.html#t:Traversable
> 
> e.g.
> 
> Prelude> :m Data.Map Data.Traversable 
> Prelude Data.Map Data.Traversable> let mymap = insert 1 "bubu" $
> insert 2 "baba" $ empty Prelude Data.Map Data.Traversable> traverse
> print mymap "bubu"
> "baba"
> fromList [(1,()),(2,())]
> Prelude Data.Map Data.Traversable> 
> 
> 

Thanks for pointing me to Traversable. Now I used Traversable.mapM
which worked fine and seems to be the "traversable" counterpart of mapM_
from Control.Monad.


It didn't make much of a difference in runtime doing it without toList.
I'm not quite sure if it is really more efficient or not. Perhaps I
would have to create dictonary with some millions entries in order to
see a noticable difference?



-- 
Manfred






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

Message: 5
Date: Sun, 15 May 2011 11:34:33 +0200
From: Matthias Guedemann <[email protected]>
Subject: Re: [Haskell-beginners] Printing the entries of a Data.Map m
To: "beginners\@haskell.org" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Hi Manfred

> It didn't make much of a difference in runtime doing it without toList.
> I'm not quite sure if it is really more efficient or not. Perhaps I
> would have to create dictonary with some millions entries in order to
> see a noticable difference?

Probably, Haskell is not very deterministic for memory / runtime
forecasts :-)

In theory there should be no difference in complexity, both need one
sweep over all entries of the Map. There could perhaps be a constant
cost for constructing the list. Nevertheless, laziness should make it
possible to run in constant space, as neither the list, nor the
transformed Map is used. So differences are probably small.

But is possible, take some measurements and report, not just runtime,
but also heap space usage.

regards
Matthias



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

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


End of Beginners Digest, Vol 35, Issue 29
*****************************************

Reply via email to