Skip to content

Instantly share code, notes, and snippets.

View rybla's full-sized avatar

Henry Blanchette rybla

View GitHub Profile
@rybla
rybla / StackMachineCompiler.agda
Created October 2, 2026 16:07
Simple stack machine compilers in Agda. Demonstrates converting from a concatenation-based compiler to a tail-recursive compiler.
open import Data.Nat using (ℕ; _+_)
open import Data.Bool using (Bool; true; false)
open import Data.List using (List; []; _∷_)
open import Data.Product using (_×_; _,_)
open import Data.Unit using (⊤; tt)
-- #region Types, Contexts, and Environments
data Ty : Set where
NatTy : Ty
@rybla
rybla / Main.hs
Created August 20, 2026 17:22
Haskell Servant demo of OpenAPI 3.0, swagger-ui, and static file serving
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
-- #region imports
import Data.Aeson (ToJSON)
import Data.OpenApi (OpenApi, ToSchema)
@rybla
rybla / Main.hs
Last active August 5, 2026 17:55
Using domains to construct a non-positive datatype for the untyped lambda calculus
--------------------------------
-- Embedding and Projecting
--------------------------------
-- | Embedding and projection between `a` and `b`. Note that `project` can fail.
data EP a b = EP
{ embed :: a -> b,
project :: b -> Maybe a
}
@rybla
rybla / apply.agda
Created July 16, 2026 18:11
A simple "apply"-like Agda macro.
open import Reflection
open import Data.Unit
open import Data.List
--------------------------------
-- "apply" macro
--------------------------------
-- Helper function for `apply` macro.
-- This function structurally recurses on `φ` (the type of `f`).
@rybla
rybla / Cargo.toml
Last active December 11, 2025 17:33
In Rust, using Maud library to generate a single-page HTML app for fuzzy-filtering a list read from a text file
[package]
name = "maud-example-fuzzy-filter-list"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.100"
maud = "0.27.0"
@rybla
rybla / proof.md
Created November 27, 2025 11:27
keyoxide identity verification

$argon2id$v=19$m=512,t=256,p=1$gw0nMXKedsmEA5rZ6Fv23w$Rc69s3MGERPKFCyiChyBeikFwh6R2WNordBaWd6f6rk

@rybla
rybla / DependentRecord.hs
Last active August 5, 2025 16:46
dependent record fields in Haskell
{-
This module demonstrates a neat feature in Haskell that I commonly use in TypeScript.
For example, in TypeScript, I often do something like this:
```
type Person
= { name: string }
& ( { isAnnotated: false }
@rybla
rybla / newtype.ts
Created July 9, 2025 20:22
newtype experiment in typescript
import { do_ } from "@/utility";
type Newtype<R extends object, S extends keyof R, T> = R[S] extends void
? R & T
: never;
const X1: unique symbol = Symbol();
type X1 = Newtype<{ [X1]: void }, typeof X1, number>;
const X2: unique symbol = Symbol();
@rybla
rybla / server.ts
Created February 10, 2025 22:24
simple HTTP server using Bun
const serve_dir = "docs"
const port = 8000;
Bun.serve({
port,
async fetch(req) {
const url_str = req.url.endsWith("/") ? `${req.url}index.html` : req.url
const url = new URL(url_str);
const filePath = `${serve_dir}${url.pathname}`;
console.log(`GET ${filePath}`)
@rybla
rybla / DFS.purs
Last active December 31, 2024 00:11
printing levels of a tree on separate lines
-- Solution 2: using breadth-first search
module Main where
import Prelude
import Data.Array as Array
import Data.Foldable (foldM, traverse_)
import Data.Traversable (traverse)
import Data.Tuple.Nested ((/\))