Porting Coreutils to Koka
06 Apr 2026I like to explore different programming languages, and I often try them out but most of them ends up as a “Hello World” in a folder I never reopen, digital fossils of a Saturday afternoon curiosity… My actual day-to-day has been settled for a while: Kotlin when I’m building for the web, Rust when I need a CLI tool. I do think about them a lot, but their syntax, semantics, and functionality don’t tickle me the same way anymore.
Then Koka came along…
Why Koka
It’s a research language from Microsoft Research. Functional, but not in the way that usually makes me bounce off after an afternoon.
The dot selection syntax was the first thing that felt right. Coming from Kotlin, I’m used to chaining: names.filter(is-hidden).sort(cmp).foreach(println). Koka lets me write like that. No inside-out nesting. Data flows left to right, which is how I think about it anyway.
But what really got me was the effect system. In most languages, a function signature tells you what goes in and what comes out. In Koka, it also tells you what the function does. A signature like fn(path) -> <fsys,exn> list<string> says: this touches the filesystem and might throw. It’s right there on the tin and not buried in documentation.
The compiler enforces it. There is no way to sneak in a side-effect, type systems are great like that. It’s “honest programming” in a way.
Porting ls
I don’t learn languages from tutorials. I need a real problem. So I started koka-labs, where I’m porting ls and wc from GNU Coreutils. First up: ls.
ls looks simple. List files, print strings. But a proper implementation touches a lot:
- Sorting I had to write an insertion sort to be able to reverse sort and get a feel of how
Kokahandles recursion. - File metadata Hidden files, permissions, timestamps. This is where I’ll hit the boundary between pure logic and actual OS interaction, that will be fun when I get to more “advanced” listing.
- Perceus Koka’s reference counting system. This is what makes functional code run at speeds you wouldn’t expect from a language without manual memory management.
Working through it piece by piece, following the GNU philosophy, has been a good way to see how Koka keeps things clean while dealing with the mess of a real operating system.
I have even done some C to implement missing features in stdlib needed for ls -F. This was super-easy, I created a C file in the same directory with a couple of small functions and then it was just to import and wire it up.
// Import my C code
extern import
c file "fs-inline.c"
// C FFI
extern is-symlink(p : string) : fsys bool
c "kk_os_is_symlink"
What stands out so far
The effect system changes how I structure code. When side effects are visible in the types, separatng pure logic from IO becomes natural. The language makes that the easiest path.
Perceus is the other thing, functional languages have a reputation for being slow or memory-hungry. Koka’s approach to reference counting gives you immutability without the usual performance cost.
No rush
There’s no timeline on this, and no requirements. Just a compiler and a rabbit hole. I’ll keep porting tools and writing about what I find.
The repo is public if you want to follow along.