Boost logo

Boost Users :

Subject: Re: [Boost-users] [Tuple] What's the point?
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2009-07-11 09:33:13


Zachary Turner wrote:
> I didn't say they explicitly wrote in the standard "tuples cannot be
> treated as sequences by design", I said that it was a conscious design
> decision not to allow tuples to be treated as sequences. Lisp is the
> exception which I forgot about, if there are other widely used
> functional languages that allow one to treat tuples as sequences that
> I'm not aware of then I'd be interested to know what they are.
>
Are you talking about treating tuples as sequences, or simply about
heterogenous sequences? Because even Haskell has the latter
(Data.HList). Incidentally, Haskell's inability of writing a generic
function that operates on tuples of any size is considered a weakness by
most sources I have read.
> For starters, the word "sequence" implies (in the mathematical sense)
> that there is a possibility of the length being unbounded.
This would be relevant if we claimed that tuples *are* sequences,
instead of that we can treat them as fixed-length sequences, which is
all Fusion's for_each does.
> I consider it a C++ design problem that there are actually situations
> where iterating over elements of a tuple is the "quickest" way to
> accomplish something. When you're iterating over a collection and
> performing some operation on the items in the collection, the elements
> neecssarily having something in common otherwise the operation
> wouldn't make sense. But at the same time, the common aspect is
> determined by the function, not by any aspect of the types themselves.
> From a theoretical perspective I think it's better to approach this
> with typeclasse
C++03 only has implicit typeclasses in the form of implicit requirements
and documentation. But to have such requirements is indeed a (implicit)
precondition of using for_each. For example, you place the implicit
requirement of all types being OutputStreamable by doing a for_each that
inserts each element into cout.
You've lost track of your argument here, though. Typeclasses in Haskell,
for example, still don't allow a list to be heterogenous. So are you
saying now that it's OK to treat tuples as sequences if all elements are
instances of some typeclass (conform to some concept)? Because, as I
just said, this is actually a precondition to using for_each.

Sebastian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net