Distributed Computing Seminar: Mapreduce Theory and Implementation
Distributed Computing Seminar: Mapreduce Theory and Implementation
f
Fold
fold f x0 lst: ('a*'b->'b)->'b->('a list)->'b
Moves across a list, applying f to each element
plus an accumulator. f returns the next
accumulator value, which is combined with the
next element of the list
f f f f f returned
initial
fold left vs. fold right
Order of list elements can be significant
Fold left moves left-to-right across the list
Fold right moves from right-to-left
SML Implementation:
fun foldl f a [] = a
| foldl f a (x::xs) = foldl f (f(x, a)) xs
fun foldr f a [] = a
| foldr f a (x::xs) = f(x, (foldr f a xs))
Example
fun foo(l: int list) =
sum(l) + mul(l) + length(l)
e.g.: [1, 4, 8, 3, 7, 9]
[0, 1, 5, 13, 16, 23, 32]
A More Complicated Map Problem
...
map map
Data store 1 Data store n