osa1.net - All posts

http://osa1.net

6 posts

Tech

Subscribe via RSS

  1. Coherence and orphan instance rules

    Typeclasses are an overloading mechanism that allows compile time or runtime polymorphism. A typeclass method call like m a b ... (or a.m(b, ...) in Rust) resolves to a concrete method based on the type arguments passed to the method. class ToString t where toString :: t -> String instance ToString Bool where toString = undefined instance ToString Int where toString = undefined f = toString (123 :: Int) g = toString True toString here is overloaded: the two calls to the same method actually…

    0
  2. Unification and impl search

    At a high level Haskell’s typeclasses and Rust’s traits are the same feature, but they also differ quite a bit in details. Here’s an example: struct A; trait C<T> {} impl<T> C<T> for Option<T> {} // ∀ T . C<Option<T>, T> fn f<P, Q>(p: P, q: Q) where P: C<Q> {} fn main() { f(None, A); } - {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} data A = A class C a b instance C (Maybe t) t f :: C p q => p -> q -> () f _ _ = () main :: IO () main = pure (f Nothing A) The Rust code type checks,…

    0
  3. Macros in Fir

    Fir macros are fully deterministic programs that are distributed separately and that can introspect into the using program’s type-checked AST definitions. Deterministic execution of macros is necessary to be able to Cache macro results in the language server and between compilation of a package during development. Avoid the issues with build scripts in many languages that can run arbitrary code when compiling a package, causing all kinds of security nightmares. Potentially distribute packages…

    0
  4. Languages should have opinionated interop features

    A lesson we can derive from Rust’s error handling and async libraries, and Haskell’s effect system libraries, is that languages need to have opinionated (and efficient, flexible) interop features. If not and the language is flexible enough (with an expressive type system, and maybe also with metaprogramming features), users create their own solutions and the ecosystem gets fragmented. Consider error reporting. Without a convenient way of error handling built into the language, a library for…

    0
  5. A text editor I worked on in 2021-2023

    I was just going through old files and saw a cool video of an old project that I thought I should share. In January 2021 I started working on a new text editor. Zed didn’t exist publicly at the time (it must’ve been under development) and two projects were getting a lot of hype: Alacritty because of its renderer Tree-sitter because IIRC Neovim was about to ship built-in support for tree-sitter grammars for syntax highlighting Inspired by these two developments, I started implementing my own…

    0
  6. Fir now compiles to C (+ extensible named types, associated types, modules, and more)

    One of my original goals with Fir was to bootstrap it as early as possible. I was so determined, I committed the first code for the self-hosted compiler in the 322nd commit, on 11 April 2025, after less than a year of development in the open source1, when it was barely usable. To understand how early this is, we’re currently on commit 1,052, and in my opinion it only recently became somewhat usable. Unsurprisingly, this turned out to be a challenge, and I had to accept the fact that a compiler…

    0