Can we implement
functional data structures
in a systems programming language?
Can we implement
persistent vectors
in C++?
template <
typename HeapPolicy, ⟵―― malloc_policy, gc_policy, ...
typename RefCountPolicy, ⟵―― no_refcount_policy, atomic_refcount_policy, ...
typename TransiencePolicy, ⟵―― gc_transience_policy, ...
...
>
struct memory_policy;
vector<int> myiota(vector<int> v, int first, int last)
{
for (auto i = first; i < last; ++i)
v = v.push_back(i);
return v;
}
vector<int> myiota(vector<int> v, int first, int last)
{
auto t = v.transient();
for (auto i = first; i < last; ++i)
t.push_back(i);
return t.persistent();
}
vector<int> myiota(vector<int> v,
int first,
int last)
{
auto t = v.transient(); ⟵―― id: #
for (auto i = first; i < last; ++i)
t.push_back(i);
return t.persistent();
}
vector<int> myiota(vector<int> v,
int first,
int last)
{
auto t = v.transient();
for (auto i = first; i < last; ++i)
t.push_back(i);
return t.persistent();
}
vector<char> say_hi(vector<char> v)
{
return v.push_back('h') ⟵―― named value: v
return move(v).push_back('h') ⟵―― moved value
.push_back('i') ⟵―― anonymous value
.push_back('!'); ⟵―― anonymous value
}
and they compose ➡ say_hi(say_hi(...))
Can we implement
persistent data structures
in a systems programming language?
only 1 X to 1.5 X overhead