This paper describes FC++: a rich library supporting functional programming in C++. Prior approaches to encoding higher order functions in C++ have suffered with respect to polymorphic functions from either lack of expressiveness or high complexity. In contrast, FC++ offers full and concise support for higher-order polymorphic functions through a novel use of C++ type inference.Another new element in FC++ is that it implements a subtype polymorphism policy for functions, in addition to the more common parametric polymorphism facilities. Subtype polymorphism is common in object oriented languages and ensures that functions in FC++ fit well within the C++ object model.Apart from these conceptual differences, FC++ is also an improvement in technical terms over previous efforts in the literature. Our function objects are reference-counted and can be aliased without needing to be copied, resulting in an efficient implementation. The reference-counting mechanism is also exported to the user as a general-purpose replacement of native C++ pointers. Finally, we supply a number of useful functional operators (a large part of the Haskell Standard Prelude) to facilitate programming with FC++. The end result is a library that is usable and efficient, while requiring no extensions to the base C++ language.
[1]
Peter G. Harrison,et al.
Functional Programming
,
1988
.
[2]
Oleg Kiselyov.
Functional style in C++: closures, late binding, and Lambda abstractions
,
1998,
ICFP '98.
[3]
Bjarne Stroustrup,et al.
A history of C++: 1979–1991
,
1993,
HOPL-II.
[4]
Philip Wadler,et al.
Comprehending monads
,
1990,
Mathematical Structures in Computer Science.
[5]
Michael J. Vilot,et al.
Standard template library
,
1996
.
[6]
Martin Odersky,et al.
Pizza into Java: translating theory into practice
,
1997,
POPL '97.
[7]
Alexander A. Stepanov,et al.
C++ Standard Template Library
,
2000
.
[8]
Jennifer Hamilton.
Montana Smart Pointers: They're Smart, and They're Pointers
,
1997,
COOTS.
[9]
Brian Foote,et al.
Designing Reusable Classes
,
2001
.
[10]
Laurent Dami,et al.
More Functional Reusability in C / C++ / Objective-c with Curried Functions
,
1991
.
[11]
Konstantin Läufer,et al.
A Framework for Higher-Order Functions in C++
,
1995,
COOTS.
[12]
John Hughes,et al.
Report on the Programming Language Haskell 98
,
1999
.