English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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