
On Tue, Jul 17, 2012 at 03:01:39PM +0200, Thomas Bach wrote:
On Sat, Jul 14, 2012 at 08:35:44PM -0400, Brent Yorgey wrote:
On Fri, Jul 13, 2012 at 06:02:02PM +0200, Thomas Bach wrote:
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.
The problem is your 'summation' function:
summation :: Num b => [(a, b)] -> (a, b)
In fact, it is impossible to implement something with this type which works for all inputs. If you get the empty list as input, there is no way to make up a value of type 'a' in the output tuple.
It really is not that big of a deal. As I'd assume that Hadoop guarantees that at least one line will be passed to the reducer. But, just out of curiosity: wouldn't this be a case where monads are applied? Say, `Maybe'? So that the type becomes
summation :: Num b => [(a, b)] -> Maybe (a, b)
Yes, wrapping the return type in Maybe could be a good idea indeed. You say "wouldn't this be a case where monads are applied", but you are jumping too far ahead: using Maybe in this way is a good idea no matter whether you happen to know that Maybe is an instance of Monad or not. Likewise, you could work with a function of this type without using the Monad interface at all. Using the Monad interface might simplify some of the code but it is by no means required. -Brent