From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-11-28 16:29:40
From: "Mat Marcus" <mmarcus_at_[hidden]>
> Here are some questions regarding functional programming literature:
> * Is it better to spend time studying Haskell, ML, or Scheme?
Let me first emphasize that I'm not an expert in FP.
I would personally recommend learning Haskell or Clean (both are lazy and pure
functional languages) first. I have never programming in SML, but I have
programmed in Ocaml. Scheme and Lisp have far too many ((((())))) for my
> Which is closer in spirit to template metaprogramming?
The C++ template mechanism is basically:
- weakly typed (Template metacode is interpreted when C++ code is compiled.
Metatype errors typically, but not necessarily, result in C++ compiling
- strict (parameters are evaluated before function expansion),
- pure (destructive updates are not allowed),
The C++ template mechanism doesn't support many powerful features found in
(modern) functional programming languages. However, some of these features can
be simulated with careful template metaprogramming.
> That is, which book
> will pay higher dividends for compile time C++ idioms: Haskell: The
> Craft of Functional Programming, ML for the Working Programmer, or
> Structure and Interpretation of Computer Programming? Perhaps
> Peyton-Jones's book or another would be most useful.
I personally liked the Haskell book a lot. Well written, easy to understand
and the propaganda level was acceptable.
> * What are the mappings between functional programming language
> concepts and C++ compile-time programs?
A very good question! That is the reason why I started writing the TMPL
document. I'm not done yet, but I'd definitely like to see such a document.
Many things, such as parameterized modules found in some FP languages can be
simulated using C++ template metaprogramming.
> I understand the basics about
> applicative style, control constructs, and recursion but I want to go
> further. Where can I learn more about suspensions, algebraic modules,
> strictness, pureness, and pattern matching. Vesa?
Most of the concepts you mentioned above are explained rather well in the
The term "suspension", as used in my TMPL document, was invented by me. It
simply means that the suspended template has not yet been instantiated.
Suspension are introduced and supported as a language concept, because they
are quite useful in practice. Some strict functional programming languages
have similar "extensions" for introducing laziness into the language.
Algebraic types aka variants aka discriminated unions are not the same as
Variants are inspected using pattern matching (pattern matching the
constructors of the variant types). However, the pattern matching capabilities
of the C++ template mechanism are so weak, that I would avoid using pattern
matching (or partial specialization) as much as possible. Partial
specialization is sometimes nice, but has the effect that the code using
pattern matching is tied to a single data structure (a single variant type).
Modules are simply that. A clearly defined interface and a hidden
implementation. You can build abstract datatypes using modules. Personally, I
would stay away from pattern matching in C++ template metaprogramming, and
build algebraic types using C++ techniques that more closely correspond to the
module systems found in FP languages. This was reflect in the TMPL document,
which placed algebraic types and modules under the same umbrella.
Strictness means that function parameters are evaluated before the function is
evaluated. In lazy (as opposed to strict) languages, parameters are evaluated
as they are needed.
Pureness means that the language does not allow mutating side-effects. All
"variables" are actually constants.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk