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
map and fold
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: map and fold
What is the relationship between map and fold?

It seems like if you have a X.fold plus an constructor
which adds an element to an existing container Y.t
you can define a kind of map which copies elements of
'a X.t into 'b T.t given an element map f: 'a -> 'b.

In STL the algorithm accumulate can do this, given
a start and end iterator for the input container,
and an insert iterator for the output container.

Anyhow it 'feels' like the fold is a container destructor,
and the constructor is a kind of 'dual' of fold. Map is then
just a combination of the fold with a special case of
the constructor function.. hmm. Any hint what the formal
symmetry is here?

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: