haskell,ghc,real-world-haskell

This should work: ghc -o simple Main.hs SimpleJSON.hs Or even something like this should work: ghc -c SimpleJSON.hs ghc -c Main.hs ghc -o simple Main.o SimpleJSON.o Or as @chi points out, you can use this: ghc --make SimpleJSON.hs Main.hs ...

The recommended time functions have changed. Data.Time etc. from the time package is a complete and more logical rewrite of Haskell's time functions. To quote the top of http://hackage.haskell.org/package/old-time-1.1.0.2/docs/System-Time.html: The standard time library from Haskell 98. This library is deprecated, please look at Data.Time in the time package instead. ...

There is an interaction going on between two instances of readsPrec: the readsPrec you defined for instance Read Color the readsPrec defined by the Prelude for instance Read [a] Let's call the readsPrec in #2 readsPrecList. When evaluating read "[Red]" :: [Color] what first happens is the readsPrecList is called....

You must carry generator into pure process (chaining new random generator state) randomR_nTimes_rec :: (RandomGen g, Random a) => Int -> (a, a) -> g -> ([a], g) randomR_nTimes_rec 0 _ g = ([], g) randomR_nTimes_rec n i g = (x:xs, g'') where ( x, g' ) = randomR i...

haskell,recursion,real-world-haskell

So I think what you're saying is that you know how to recursively append to a list by doing something like foobar :: [x] -> [y] foobar ( []) = [] foobar (x:xs) = {- ...stuff... -} : foobar xs but you have no idea how to do that with...

haskell,real-world-haskell,ppm

Netpbm contains tools to convert popular formats to pbm. pngtopnm < file.png | ppmtopgm | pgmtopbm > file.ppm pngtopnm may convert directly to pgm or ppm it depends on the the colour-space of the input file. you may need pnmtoplainpnm on the end of the pipeline if your program is...

haskell,monads,real-world-haskell

Your code is very similar to the Writer [a] monad, and I don't think there is a simpler way of fixing it than closing the gap in all but naming. Specifically: Since a monad must allow an arbitrary result type, the type of the effect part cannot depend on the...

What @simonzack is alluding to is that you should write listlen and sumx as folds. Here is listlen written as a fold: listlen :: [a] -> Int listlen xs = go 0 xs -- 0 = initial value of accumulator where go s [] = s -- return accumulator go...

The relevant definitions are available in the Report, and look like this: read :: (Read a) => String -> a read s = case [x | (x,t) <- reads s, ("","") <- lex t] of [x] -> x [] -> error "Prelude.read: no parse" _ -> error "Prelude.read: ambiguous parse"...

In Haskell source files, top-level definitions like f shouldn't be introduced with a let - just write f [] = [] f ('\n':',':a) = f ('\n' : a) f (a:b) = a : f b Also you need make sure that the left-hand side of each clause in a definition...

The difference between: *Main> return 1 :: Maybe Integer And *Main> return Nothing :: Maybe String Is that 1 has type Integer, but Nothing has type Maybe a. If you want to wrap Nothing into another Maybe value, you should specify the type for Nothing like this: *Main> return Nothing...

regex,haskell,haskell-platform,real-world-haskell

According to the Haskell Wiki (https://wiki.haskell.org/Regular_expressions#regex-base): Executive summary: If you want a bug-free and/or portable POSIX extended regular expression library to use from Haskell, then regex-posix will not help you. You should use the regex-tdfa package instead. Try using the tdfa regex package from http://hackage.haskell.org/package/regex-tdfa. If you are not familiar...

xs' would be bound to the string "ello". xs would be bound to the string "hello". The @ pattern lets you give a name to a variable while also matching its structure and possibly giving name to the components....

haskell,concurrency,parallel-processing,mapreduce,real-world-haskell

In this line: result = mapReduce Control.Parallel.Strategies.parMap stringToWordCountMap Control.Parallel.Strategies.parList reduceWordCountMaps fileInLines for a Strategy you should provide a value like rpar or rseq. See this documentation for other defined strategies. So the above line should look like: result = mapReduce rpar stringToWordCountMap rpar reduceWordCountMaps fileInLines I also got some indentation...