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. Re: Comments on Map/Reduce Code (Thomas Bach)
2. Graph Coloring Library? (Alec Story)
----------------------------------------------------------------------
Message: 1
Date: Fri, 13 Jul 2012 18:02:02 +0200
From: Thomas Bach <[email protected]>
Subject: Re: [Haskell-beginners] Comments on Map/Reduce Code
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi Brent,
thanks for your suggestions. I got further suggestions as a private
e-mail and finally came up with the following solution ? suggestions
welcome:
==================== mapper.hs ====================
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TLIO
postFix :: TL.Text
postFix = TL.pack "\t1"
formatter :: TL.Text -> TL.Text
formatter x = TL.append x postFix
main = TLIO.interact pipeline
where words = TL.words
format = map formatter
pipeline = TL.unlines . format . words
===================================================
==================== reducer.hs ===================
import qualified Data.Text.Lazy.IO as TLIO
import qualified Data.Text.Lazy as TL
import qualified Data.List as L
import Data.Function (on)
tuppleize :: TL.Text -> (TL.Text, Int)
tuppleize line = (word, num)
where words = TL.words line
word = head words
num = read . TL.unpack $ last words
group :: Eq a => [(a, b)] -> [[(a, b)]]
group = L.groupBy ((==) `on` fst)
summation :: Num b => [(a, b)] -> (a, b)
summation ((x, y):xs) = (x, y + sum (map snd xs))
formatter :: (TL.Text, Int) -> TL.Text
formatter (w, i) = TL.append w (TL.pack ('\t':show i))
main = TLIO.interact pipeline
where tuples = TL.lines
group_tuples = group . map tuppleize
sum_tuples = map (formatter . summation)
pipeline = TL.unlines . sum_tuples . group_tuples . tuples
===================================================
The reducer still throws an error when piping in an empty
newline. But, I'm not sure, what a proper solution for this could be.
On Tue, Jul 10, 2012 at 10:19:48AM -0400, Brent Yorgey wrote:
> On Thu, Jul 05, 2012 at 03:50:32PM +0200, Thomas Bach wrote:
>
> Instead of using a chain of ($), it's generally considered better
> style to use a chain of (.) with a single $ at the end, like
I often find myself trying different combinations of ($), (.) or
putting things in brackets, when the compiler throws an error on
me. Without really knowing why things sometimes work out and sometimes
don't. I find this part especially confusing!
Regards,
Thomas
------------------------------
Message: 2
Date: Fri, 13 Jul 2012 16:43:28 -0400
From: Alec Story <[email protected]>
Subject: [Haskell-beginners] Graph Coloring Library?
To: [email protected]
Message-ID:
<CAKcn5so+2wJ8F_4aDyPHH=r55x1mhlrxfcsfxxs_lt-mlmf...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I have a problem where I need to find the smallest k-coloring for a graph
that represents conflicts between objects. Is there a Haskell library that
will do this for me? I'm not particularly concerned about speed, and it's
unlikely that I'll generate really bad edge cases, but I'd prefer to do
something other than write the really bad try-every-case algorithm.
--
Alec Story
Cornell University
Biological Sciences, Computer Science 2012
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120713/8f63794b/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 49, Issue 14
*****************************************