# NOT RUN {
# We generate some random numbers.
numbers <- rnorm(10)
# The sum is easiest computed with the `sum` function:
sum(numbers)
# If we wanted to implement `sum` ourselves, we can use a right fold to do
# so:
Reduce(`+`, numbers, 0.0)
# With this new function we do not need a neutral element any more, but give
# up the possibility to fold empty lists.
foldr1(`+`, numbers)
# }
Run the code above in your browser using DataLab