[Haskell-beginners] Comments on Map/Reduce Code

Thomas Bach thbach at students.uni-mainz.de
Tue Jul 17 15:01:39 CEST 2012

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)

Or is the semantic behind monads a different one?


More information about the Beginners mailing list