r/VibeCodedLanguages • u/paulhaahr • 3d ago
Quest, the language from Luca Cardelli's Typeful Programming (1989)
I read Luca Cardelli's paper Typeful Programming when I was an undergrad and I was taken with Quest, the language it used to illustrate its ideas. It's a language in the ML family which Cardelli used to experiment with integrating subtyping and the object-oriented style with more classical functional programming. It introduces a three-level type system of values, types, and kinds (the types of types). No implementation was ever made public, as far as I know, and the discourse around programming languages went in other directions.
Late this summer, I was looking around for a spare-time, greenfield project to play with agentic coding on. Specifically, I wanted to see if I could build something that was readable and I would feel good about as a codebase, but where I wouldn't write a line of code myself. I knew I wanted to build a compiler, but I didn't want to do a new language, which would have involved much more language design than implementation, and, at the same time, I didn't want to do another implementation of a popular language. I landed on Quest. One of the questions for me was whether the models would be able to cleanly write a self-hosted implementation in a language they'd seen almost nothing of. (As far as I can tell, other than this project, the only Quest code you can find on the internet is a couple of hundred lines in papers Cardelli wrote.)
I did a lot of planning of how I wanted the project structured in advance, but learned a lot as I went along, reviewing the generated code, writing small programs in Quest, and discussing with the models how to build various aspects of the system. It was very helpful having models that have effectively read all of programming language, type theory, and compiler literature as debating partners. Over about three months, I had various Gemini and Claude models:
- build a bootstrap interpreter and transpiler to C in Python
- convert the interpreter and transpiler to self-hosted Quest
- design and implement basic libraries to make the language usable for self-hosting
- write a native arm64 backend in Quest
- build a non-moving Immix-style garbage collector
- convert the MLton performance suite into Quest for tuning (the arm64 compiler runs the benchmarks about 50% slower than MLton on average; optimizing and then compiling through C with Clang is only 15% slower)
- make the arm64 compiler work as a JIT for the REPL and scripting
- make a WASM version of the compiler and JIT (which you can try in a REPL)
- write an LSP to use with VS Code (or your favorite tools)
- integrate the REPL with Jupyter for interactive use
I'm pretty confident that this is the largest Quest codebase that's ever existed; it's about 135K lines of Quest, not counting tests or the C and Python code. It's probably not "idiomatic Quest," if that concept exists, because the models didn't naturally take advantage of language-specific features such as kinds.
Is Quest a language I'd rationally choose to use? Not really. It's got a lot of complexity in the type system to integrate functions and objects, but doesn't pay it off with a useful object system. Subtyping in Quest is quite clean, but modeling dynamically dispatched methods and inheritance in the language involves a lot of awkward machinery around shared closures – it works, but it feels like a simulation of an object-oriented language and not something that's native. (OCaml, which came later, is a better "objects in ML" language. And Cardelli and Martin Abadi's book A Theory of Objects goes in a different direction for its integration of objects and functions.) The module system looks powerful and goes quite far to let you have multiple implementations of interfaces, but, in practice, because you can't use a manifest type without naming the implementing module, it's hard to swap implementations. And the syntax has some quirky bits (no operator precedence, a syntax halfway between Modula-2 and early Haskell, "_" as a separator like ".") which make it rather un-ergonomic. At the same time, I've been writing a few toys with it inside Jupyter and it feels right – interactive iteration works well with the type system catching errors.
Were the models able to do a good job writing Quest? Very much so. When they made mistakes, it was often because they carried over habits from other languages, such as using "_" as a character in identifiers or assuming standard operator precedence rules; this was the same sort of I trap fell into. (I actually made more of these mistakes than the models did, such as forgetting that Quest doesn't use commas to separate function arguments.)
This has been a fun project for me to explore this programming language I've long been curious about, while seeing if I could build a well-designed large system using agentic tools. In the end, I'm happy with the result; I think it's as good as I could have done by hand, but took probably 1% of the effort.