Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
The Map and Fold
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-12-23 (14:48)
From: lloydmoore <lloyd@e...>
Subject: The Map and Fold
In reply to the relationship between map and fold, The fold difference
is that only a single entity is returned (the accumulator) as opposed
to, if you like, a place for each original array/list/vector member.
Fold is indeed an extended specialized version of map because it has to
perform both functions... iterate over the elements and use them as
function arguments but it then goes one step further and accumulates the
results as it iterates.

Using STL, this would be the difference between mapping a X.t into b X.t
and stopping there, or going the extra step and summising your new set
of results 'on the fly' as it were.

Hope this makes sense :D