Skip to content

Commit 92e76bf

Browse files
committed
Various fixes for the release.
1 parent c2c83b0 commit 92e76bf

File tree

10 files changed

+1015
-214
lines changed

10 files changed

+1015
-214
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ CLIBS = -lc -lgc
3131
CLIB = $(OBJS)
3232

3333
libf.so: $(OBJS)
34-
$(CXX) -shared -o libf.so $(OBJS) $(CLIBS)
34+
$(CXX) -shared -o libf++.so $(OBJS) $(CLIBS)
3535

3636
clean:
37-
rm -f *.o *.s *.i main
37+
rm -f *.o *.s *.i
3838

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
LIBF 0.2 -- Reinventing C++ as a Pure Functional Programming Language
2-
=====================================================================
1+
LIBF++ 0.2 -- C++ as a Pure Functional Language
2+
===============================================
33

4-
Libf is a library that supports pure functional programming in C++.
4+
LibF is a library that supports pure functional programming in C++.
55

66
Modern C++ purports to be a "multi-paradigm" programming language supporting
77
procedural, object-oriented and functional features. In reality however, most
@@ -23,17 +23,17 @@ the above code can be translated into:
2323

2424
F::Vector<int> xs;
2525
for (int i = 0; i < 10; i++)
26-
xs = push_back(xs, i);
26+
xs = F::push_back(xs, i);
2727

2828
Unlike the standard C++ library, LibF objects are *immutable*. This makes the
2929
following code possible:
3030

3131
F::Vector<int> xs;
3232
for (int i = 0; i < 5; i++)
33-
xs = push_back(xs, i);
33+
xs = F::push_back(xs, i);
3434
F::Vector<int> ys = xs; // Save the current xs
3535
for (int i = 0; i < 5; i++)
36-
xs = push_back(xs, i);
36+
xs = F::push_back(xs, i);
3737
printf("%s\n%s\n", c_str(show(ys)), c_str(show(xs)));
3838

3939
This code will print:
@@ -45,8 +45,9 @@ The old object `ys` was unaffected by the changes made to its copy `xs`. And
4545
just like stdlib++, the LibF vector `push_back` operation is still O(1) --
4646
although the constant factors may differ (see below).
4747

48-
Using C++ as a functional programming language has several advantages.
49-
Namely:
48+
With immutable objects, it is possible to use (a subset of) C++ as a pure
49+
functional programming language. Compared to other functional languages, C++
50+
has several advantages, namely:
5051

5152
* *Compiler Support*. C++ is supported by several stable, mature optimizing
5253
compilers.
@@ -152,10 +153,11 @@ In principle, this can be replaced with:
152153

153154
F::Vector<int> xs;
154155
for (int i = 0; i < 10; i++)
155-
xs = push_back(xs, i);
156+
xs = F::push_back(xs, i);
156157

157-
Although each `push_back` operation is still O(1), the constant factors differ
158-
by a factor of 100. Instead it may be better to use a list instead, e.g.:
158+
Although each `F::push_back` operation is still O(1), the constant factors
159+
differ by a factor of 100. Instead it may be better to use a list instead,
160+
e.g.:
159161

160162
F::List<int> xs;
161163
for (int i = 0; i < 10; i++)
@@ -175,7 +177,7 @@ create your own list type:
175177
template <typename T> struct NODE;
176178
struct EMPTY;
177179
template <typename T>
178-
using LIST = Union<EMPTY, NODE<T>>;
180+
using LIST = F::Union<EMPTY, NODE<T>>;
179181
struct EMPTY { };
180182
struct NODE
181183
{
@@ -190,12 +192,12 @@ The type `LIST` is defined to be a discriminated union between the `EMPTY` and
190192
can be passed-by-copy. The index of the underlying type for a discriminated
191193
union is returned by a special `index` function. The discriminated union type
192194
can then be cast to the underlying type, and vice versa. For example, the
193-
following function reverses a `LIST`:
195+
following function reverses a `LIST` by accumulating onto `ys`:
194196

195197
template <typename T>
196198
PURE LIST<T> reverse(LIST<T> xs, LIST<T> ys)
197199
{
198-
switch (index(xs)) // Determine if xs is a node or empty.
200+
switch (F::index(xs)) // Determine if xs is a node or empty.
199201
{
200202
case LIST_EMPTY:
201203
return ys;
@@ -265,19 +267,21 @@ Unsurprisingly, constructing a `std::vector` is the fastest. The fastest for
265267
LibF is constructing a linked-list `F::List`, followed by `F::Vector`.
266268
Constructing `F::map` has about twice the overhead as the mutable `std::map`
267269
counterpart. Such results are expected (immutability has inherit costs).
270+
Note that these benchmarks assume that the garbage collector is disabled.
271+
Otherwise garbage collector overheads become a significant factor about the 3M
272+
mark.
268273

269-
The following compares the time to scan each data structure using a C++ range
270-
loop, i.e.:
274+
The following compares the time to scan each data structure using `foldl` or a
275+
C++ range loop, i.e.:
271276

272277
int sum = 0;
273278
for (auto x: xs) sum += x;
274279

275280
![Benchmarks2](http://comp.nus.edu.sg/~gregory/images/LibF_benchs2.png)
276281

277-
Note that this uses iterators, which are slower for LibF data structures
278-
compared to the mutable standard library counterparts. An alternative is to
279-
use `foldl` when appropriate, which generally faster than iterators, but is
280-
less expressive in general.
282+
Note that range loops use iterators, which are slower for LibF data structures
283+
compared to the mutable standard library counterparts. The `foldl`
284+
alternatives are faster, but are less expressive in general.
281285

282286
Library Documentation:
283287
----------------------

build.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ make bench
2929

3030
cd ..
3131

32-
for BASENAME in compare list map maybe show string tuple value vector
32+
for BASENAME in compare list map maybe "set" show string tuple value vector
3333
do
3434
examples/libf2html f${BASENAME}.h > doc/${BASENAME}.html
3535
done
3636

37+
mkdir -p libf++-0.2/
38+
mkdir -p libf++-0.2/include/
39+
mkdir -p libf++-0.2/doc/
40+
cp *.h libf++-0.2/include/
41+
cp doc/*.html libf++-0.2/doc/
42+
cp libf++.so libf++-0.2/
43+
tar cvz --owner root --group root -f libf++-0.2.tar.gz libf++-0.2/
44+
rm -rf libf++-0.2/
45+

0 commit comments

Comments
 (0)