[erlang-questions] Add a new data structure to erlang VM.

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun Jul 10 14:25:15 CEST 2016

On Sun, Jul 10, 2016 at 1:16 PM, <ok@REDACTED> wrote:

> No, I tell a lie.  The *best* thing is to NOT add a new low-level
> data structure to Erlang.  Mixing data structures between languages
> with different memory management strategies is for people who like
> pain too much.

The only time where this is somewhat acceptable is the case where the
underlying data structure can be embedded in the host language. In Erlang's
case, this demands that the underlying data structure be persistent rather
than ephemeral[0]. Some times, you can write a data structure which has
(locally) benign effects, but where the interface to that data structure is
safe from the outside. In that case, you may rewrite the data structure due
to demands of efficiency in your program.

In general though, it tend to be a better long-term stategy to implement
such a data structure in Erlang, *before* dropping to C. That way, you have
a reference implementation you can use as a test case for verifying the
correctness of the low-level embedded efficient datastructure. Also, as ok@
writes, the GC interface between different languages is often treacherous

[0] Roughly: that you can refer to older versions of the data structure in
the code. This is true for any Erlang data structure, except the process
dictionary and ETS tables. In particular, any destructive update is

[1] OCaml recently added "ephemerons" to their language for this very
reason. They allow the usual "weak" references with an elegant extra set of
rules, which allows more elegant implementations of e.g., LRU caches.
Having those in the language often allows the GC to interplay with foreign
data in a nicer way.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160710/603eeb43/attachment.htm>

More information about the erlang-questions mailing list