Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org 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 (Brent Yorgey) 2. Trouble compiling haskell platfrom (Jeff Lasslett) ---------------------------------------------------------------------- Message: 1 Date: Tue, 10 Jul 2012 10:19:48 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Comments on Map/Reduce Code To: beginners@haskell.org Message-ID: <20120710141948.ga16...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Thu, Jul 05, 2012 at 03:50:32PM +0200, Thomas Bach wrote: > Hello there, Hi Thomas, Looks pretty good. I've interspersed a few comments below. > And here is the code I've come up with: > > vince@roku:~/tmp cat mapper.hs > import qualified Data.ByteString.Lazy.Char8 as C > > postFix :: C.ByteString > postFix = C.pack "\t1" > > formatter :: C.ByteString -> C.ByteString > formatter x = C.append x postFix > > main :: IO () > main = do > contents <- fmap C.words C.getContents > C.putStr . C.unlines $ map formatter contents The above looks fine, except that generally the recommendation is to use the text package [1] for dealing with text, whereas ByteString is for binary data that you wish to manipulate as a sequence of bytes. You can get away with the above only when the text consists entirely of ASCII characters. [1] http://hackage.haskell.org/package/text > vince@roku:~/tmp cat reducer.hs > import qualified Data.ByteString.Lazy.Char8 as C > import qualified Data.List as L > > tuppleize :: String -> (String, Int) > tuppleize line = (\xs -> (head xs, read (last xs))) $ words line What happens when the line is empty? > group :: Eq a => [(a, b)] -> [[(a, b)]] > group = L.groupBy (\x y -> fst x == fst y) The above lambda can also be written as ((==) `on` fst). 'on' can be imported from Data.Function. > > summation :: Num b => [(a, b)] -> (a, b) > summation (x:[]) = x > summation (x:xs) = (fst x, (snd x) + (snd (summation xs))) Instead of using (fst x) and (snd x), you should pattern-match on x, like summation ((x,y):xs) = (x, y + ...) > formatter :: (String, Int) -> String > formatter = (\w -> (fst w ++ "\t" ++ show (snd w))) The same goes here. I would also put the w argument on the left-hand side of the =, like formatter (s,i) = s ++ "\t" ++ show i > > main = do > contents <- C.getContents > putStr . unlines $ map formatter $ map summation $ group $ map tuppleize $ > lines $ C.unpack contents Instead of using a chain of ($), it's generally considered better style to use a chain of (.) with a single $ at the end, like putStr . unlines . map formatter ... lines . C.unpack $ contents -Brent ------------------------------ Message: 2 Date: Wed, 11 Jul 2012 10:07:38 +1000 From: Jeff Lasslett <jeff.lassl...@gmail.com> Subject: [Haskell-beginners] Trouble compiling haskell platfrom To: Beginners@haskell.org Message-ID: <CAK6+hbxU5k=p0-3myvxf6j5xvao9lta7fkrg2kotvv6wtrp...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Greetings, I'm trying to recompile & reinstall the haskell platform 12.2.0.0. I have installed it successfully on a prior occasion but I decided to reinstall as I think I may have messed up my installed packages a bit while playing around with yesod. I intend to use cabal-dev or virtualenv for that in future. So I thought I'd do a clean install. I blew away my haskell platform and ghc, both of which were installed in a dir under my home dir. I also blew away my ~/.cabal/ dir. I then reinstalled by ghc 7.4.1 into ~/prg/haskell-platform-12.2.0.0. I then unpacked the sources of haskell-platform-12.2.0.0 and configured it with the prefix set to where ghc is. configure finished without error so I ran 'make'. It quits with what follows. How do I fix this?? With thanks, Jeff * Now do "make" followed by "make install" ************************************************** jeff@chunks:~/src/haskell-platform-2012.2.0.0$ make scripts/build.sh ************************************************** Scanning system for any installed Haskell Platform components... Found: HUnit-1.2.4.2 OpenGL-2.2.3.1 GLUT-2.1.2.1 html-1.0.1.2 parallel-3.2.0.2 random-1.0.1.1 QuickCheck-2.4.2 stm-2.3 syb-0.3.6.1 haskell-src-1.0.1.5 text-0.11.2.0 transformers-0.3.0.0 mtl-2.1.1 fgl-5.4.2.4 parsec-3.1.2 network-2.3.0.13 HTTP-4000.2.3 regex-base-0.93.2 regex-posix-0.95.1 regex-compat-0.95.1 xhtml-3000.2.1 cgi-3001.1.7.4 zlib-0.5.3.3 haskell-platform-2012.2.0.0 New packages to install: None! All done. ************************************************** Building alex-3.0.1 "/home/jeff/prg/haskell-platform-12.2.0.0/bin/ghc" "--make" "Setup" "-o" "Setup" "-package" "Cabal-1.14.0" Linking Setup ... "./Setup" "configure" "--package-db=../../packages/package.conf.inplace" "--prefix=/home/jeff/prg/haskell-platform-12.2.0.0" "--with-compiler=/home/jeff/prg/haskell-platform-12.2.0.0/bin/ghc" "--with-hc-pkg=/home/jeff/prg/haskell-platform-12.2.0.0/bin/ghc-pkg" "--with-hsc2hs=/home/jeff/prg/haskell-platform-12.2.0.0/bin/hsc2hs" "--enable-library-profiling" "--ghc-pkg-option=--package-conf=../../packages/package.conf.inplace" "--user" Warning: defaultUserHooks in Setup script is deprecated. Configuring alex-3.0.1... "./Setup" "build" Building alex-3.0.1... Preprocessing executable 'alex' for alex-3.0.1... src/Data/Ranged/RangedSet.hs:64:8: Could not find module `Test.QuickCheck' There are files missing in the `QuickCheck-2.4.2' package, try running 'ghc-pkg check'. Use -v to see a list of the files searched for. Error: Building the alex-3.0.1 package failed make: *** [build.stamp] Error 2 ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 49, Issue 11 *****************************************