Koka language: "FBIP: Functional but In-Place" and "Perceus memory management"

Seems like an interesting language, and maybe Julia can learn from it.

First background (and seemingly interesting in of itself):

Perceus Reference Counting
Perceus is an advanced compilation method for reference counting. This lets Koka compile directly to C code without needing a garbage collector or runtime system! This also gives Koka excellent performance in practice.

See: The Koka Programming Language

Perceus is the compiler optimized reference counting technique that Koka uses for automatic memory management […]
Normally we need to make a fundamental choice when managing memory:
[manual or GC, Perceus is the middle gound]

And: The Koka Programming Language

3.5. FBIP: Functional but In-Place

With Perceus reuse analysis we can write algorithms that dynamically adapt to use in-place mutation when possible (and use copying when used persistently). Importantly, you can rely on this optimization happening, e.g. see the match patterns and pair them to same-sized constructors in each branch.

This style of programming leads to a new paradigm that we call FBIP: “functional but in place”. Just like tail-call optimization lets us describe loops in terms of regular function calls, reuse analysis lets us describe in-place mutating imperative algorithms in a purely functional way (and get persistence as well).

Julia isn’t a pure functional language, and I’ve been very supportive of that, it being imperative.

Rick Hickey has an excellent talk against what he calls place-oriented programming (PLOP), i.e. against “in-place” (what gives Julia its speed, avoiding the GC) what imperative usually means, why functional better (for correctness, but apparently there doesn’t have to be a trade-off, at least not much slower, Koka aims for within 2x speed of C). I’ve been on the lookout for Julia packages, and found, supporting that style, i.e. with persistence, but you need to opt into using them.

1 Like