Boost logo

Boost :

From: Jeremy Maitin-Shepard (jbms_at_[hidden])
Date: 2003-10-25 20:23:10


"David B. Held" <dheld_at_[hidden]> writes:
> Well, the problem with Haskell is that it's an FP lang. ;) And
> the problem with FP langs is that they tend to be a bit
> snobbish. And that leads them to be really good at some
> things, and mediocre to really awkward at others (for instance,
> I haven't seen a convincingly elegant use of OOP in an FP
> lang, or a nice alternative). So while I like the idea of
> having the same syntax cross domains, I would like to see
> this in an MP (multi-paradigm ;) language instead.

(This post is rather off topic, but I thought I would post it anyway)

If C++ supported anonymous functions/function objects (with access to
local variables), there would be no need to use functional-programming
with libraries like boost.lambda and boost.bind.

If C++ had significant language support for template meta-programming,
there would be no need for functional programming in that domain either.

As I see it, functional programming is used in c++ primarily, if not
exclusively, when (the preferred) imperative programming is not
possible.

Imagine if C++ supported syntax like this:

typedef typename {
  type x = mpl::vector<int, bool, short, double>;
  type y = mpl::vector<float, unsigned int>;
  for(type it = begin<y>; it != end<y>; it = next<it>)
    x = push_back<x, deref<it> >;
  return x;
} my_vector;

This could be improved further by allowing operator overloading on types
(which could be used only inside these "type-mode" blocks). Note that
curly-brace-delimited block above could not contain any run-time
expressions. This could also be extended to template typedefs:

template <class Seq1, class Seq2>
typedef typename {

  for(type it = begin<Seq2>; it != end<Seq2>; it = next<it>)
    Seq1 = push_back<Seq1, deref<it> >;

  return Seq1;
} concat_sequences;

One could even allow a real "metafunction" definition:

template append_int_to_seq<class &Seq> {
  Seq = push_back<Seq, int>;
}

(If the definition contains a return statement, the metafunction returns
a type; otherwise it returns nothing)

I think I will take this any day over functional programming. The only
advantage I see in functional programming is that it allows template
meta-programming to actually be done with the existing C++.

-- 
Jeremy Maitin-Shepard

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk