[fusion] Any chance we can incorporate more folds?

I've implemented, in particular, foldr1: template< typename Sequence, typename State, typename F
typename result_of::foldr1<Sequence, F>::type foldr1( Sequence& seq, F const& f); Semantics: Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq. It is very useful for fusion sequences of possibly distinct types that have identical concepts which can be merged in some way (like generators). I very much like the folds that are included in Haskell's prelude, namely foldl, foldl1, foldr (somewhat like boost's fold), and foldr1[1]. David [1] http://www.haskell.org/onlinereport/haskell2010/haskellch20.html#x28-2310002... -- David Sankel Sankel Software www.sankelsoftware.com 585 617 4748 (Office)

AMDG David Sankel wrote:
I've implemented, in particular, foldr1:
template< typename Sequence, typename State, typename F
typename result_of::foldr1<Sequence, F>::type foldr1( Sequence& seq, F const& f);
Semantics:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
It is very useful for fusion sequences of possibly distinct types that have identical concepts which can be merged in some way (like generators).
I very much like the folds that are included in Haskell's prelude, namely foldl, foldl1, foldr (somewhat like boost's fold), and foldr1[1].
We already have reverse_fold, which makes 2/4. In Christ, Steven Watanabe

On 8/21/2010 5:21 AM, Steven Watanabe wrote:
AMDG
David Sankel wrote:
I've implemented, in particular, foldr1:
template< typename Sequence, typename State, typename F typename result_of::foldr1<Sequence, F>::type foldr1( Sequence& seq, F const& f);
Semantics:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
It is very useful for fusion sequences of possibly distinct types that have identical concepts which can be merged in some way (like generators).
I very much like the folds that are included in Haskell's prelude, namely foldl, foldl1, foldr (somewhat like boost's fold), and foldr1[1].
We already have reverse_fold, which makes 2/4.
These contributions are very welcome, David. I'd love to take them in if you also plan to write some docs to go with it :-) Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

On Fri, Aug 20, 2010 at 7:59 PM, Joel de Guzman <joel@boost-consulting.com>wrote:
On 8/21/2010 5:21 AM, Steven Watanabe wrote:
AMDG
David Sankel wrote:
I've implemented, in particular, foldr1:
template< typename Sequence, typename State, typename F typename result_of::foldr1<Sequence, F>::type foldr1( Sequence& seq, F const& f);
Semantics:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
It is very useful for fusion sequences of possibly distinct types that have identical concepts which can be merged in some way (like generators).
I very much like the folds that are included in Haskell's prelude, namely foldl, foldl1, foldr (somewhat like boost's fold), and foldr1[1].
We already have reverse_fold, which makes 2/4.
These contributions are very welcome, David. I'd love to take them in if you also plan to write some docs to go with it :-)
Sure thing. Thanks. -- David Sankel Sankel Software www.sankelsoftware.com 585 617 4748 (Office)

On Fri, Aug 20, 2010 at 7:59 PM, Joel de Guzman <joel@boost-consulting.com>wrote:
On 8/21/2010 5:21 AM, Steven Watanabe wrote:
AMDG
David Sankel wrote:
I've implemented, in particular, foldr1:
template< typename Sequence, typename State, typename F typename result_of::foldr1<Sequence, F>::type foldr1( Sequence& seq, F const& f);
Semantics:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
It is very useful for fusion sequences of possibly distinct types that have identical concepts which can be merged in some way (like generators).
I very much like the folds that are included in Haskell's prelude, namely foldl, foldl1, foldr (somewhat like boost's fold), and foldr1[1].
We already have reverse_fold, which makes 2/4.
These contributions are very welcome, David. I'd love to take them in if you also plan to write some docs to go with it :-)
Sure thing. Thanks. -- David Sankel Sankel Software www.sankelsoftware.com 585 617 4748 (Office)

On 08/20/10 16:21, Steven Watanabe wrote: [snip]
We already have reverse_fold, which makes 2/4.
fusion::reverse_fold takes the sequence as the first argument. In contrast, the haskell function takes the sequence as the last argument. That wouldn't be a big problem except if you plan to provide a variadic template: http://www.osl.iu.edu/~dgregor/cpp/variadic-templates.html version of these functions. The variadic template spec requires the parameter pack to be at the end, IOW: template<typename Op, typename State0, typename... Values) foldl(Op,State0,Values&... values); Which is exactly the way haskell orders the arguments. I know this is different than the way fusion and mpl do it; however, if arg packs (e.g. Values&... values) are to be used, then I don't see any workaround. -Larry

On 8/20/2010 11:40 PM, Larry Evans wrote:
On 08/20/10 16:21, Steven Watanabe wrote: [snip]
We already have reverse_fold, which makes 2/4.
fusion::reverse_fold takes the sequence as the first argument. In contrast, the haskell function takes the sequence as the last argument. <snip>
Fusion and mpl are trying to be consistent with the STL algorithms, not Haskell (fold == accumulate). -- Eric Niebler BoostPro Computing http://www.boostpro.com

Zitat von David Sankel <camior@gmail.com>:
I've implemented, in particular, foldr1:
template< typename Sequence, typename State, typename F
typename result_of::foldr1<Sequence, F>::type foldr1( Sequence& seq, F const& f);
Semantics:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
isn't this equivalent to fold(pop_front(seq),front(seq),f) ?

On Fri, Aug 20, 2010 at 6:43 PM, Stefan Strasser <strasser@uni-bremen.de>wrote:
Zitat von David Sankel <camior@gmail.com>:
I've implemented, in particular, foldr1:
template< typename Sequence, typename State, typename F
typename result_of::foldr1<Sequence, F>::type foldr1(
Sequence& seq, F const& f);
Semantics:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
isn't this equivalent to fold(pop_front(seq),front(seq),f) ?
Almost... fold(pop_front(seq),front(seq), flip( f ) ) where flip returns a version of f with swapped arguments. David -- David Sankel Sankel Software www.sankelsoftware.com 585 617 4748 (Office)

Zitat von David Sankel <camior@gmail.com>:
Equivalent to f(....f(f(e1,e2),e3)...) where e1 ...eN are the elements of seq.
isn't this equivalent to fold(pop_front(seq),front(seq),f) ?
Almost...
fold(pop_front(seq),front(seq), flip( f ) )
where flip returns a version of f with swapped arguments.
are you using an older version of boost? the arguments to f were swapped some time last year: libs/fusion/doc/html/fusion/change_log.html I don't know why this was done, but this might be the reason. -Stefan
participants (6)
-
David Sankel
-
Eric Niebler
-
Joel de Guzman
-
Larry Evans
-
Stefan Strasser
-
Steven Watanabe