Skip to content

Instantly share code, notes, and snippets.

@tjjfvi
tjjfvi / README.md
Last active April 14, 2024 15:31
Algebraic Effects in Interaction Nets

Algebraic Effects in Interaction Nets

(Borrowing terminology from https://unison-lang.org/, which is what prompted me to think about / write this.)

Scroll down to "Examples" to see how this would be used in practice.

The representation of abilities uses mutable references, a primitive that can be expressed naturally in interaction combinators. Here, they're implemented

@tjjfvi
tjjfvi / affine.agda
Created February 19, 2024 15:09
a reducer for the affine lambda calculus, written in Agda
open import Data.Unit
open import Data.Empty
open import Data.Product
open import Data.Bool using (Bool; true; false; not; _∧_; _∨_)
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Induction
open import Data.Fin using (Fin)
open import Relation.Binary.PropositionalEquality
open import Induction.WellFounded
@tjjfvi
tjjfvi / thin_trait_object_pointers.rs
Last active February 5, 2024 21:24
thin trait object pointers in Rust
#![feature(thin_box, ptr_metadata, unsize, extern_types, const_mut_refs, const_refs_to_cell)]
use std::{
borrow::{Borrow, BorrowMut},
boxed::ThinBox,
marker::{PhantomData, Unsize},
mem::MaybeUninit,
ops::{Deref, DerefMut},
ptr::Pointee,
};
@tjjfvi
tjjfvi / generate-weekday-regex.ts
Last active March 1, 2023 20:09
A regex matching only ISO8601-formatted dates representing weekdays
// @ts-nocheck
const charset = [..."0123456789-"];
let visitState,
x,
obj,
selfPath,
initialPath,
path;
@tjjfvi
tjjfvi / __proto__.md
Last active October 24, 2022 14:44
Object Construction with `__proto__`

Object construction with __proto__ such as

let foo = { __proto__: null }
let bar = { __proto__: Bar.prototype, abc: 123 }

is perfectly standardized and safe, unlike the unsafe and legacy Object.prototype.__proto__ getter and setter methods.

The above code is equivalent to

let foo = Object.create(null);
@tjjfvi
tjjfvi / combinatory-logic.rs
Last active May 22, 2022 15:27
Combinatory Logic in Rust `macro_rules!`
macro_rules! eq_ident {
($a:ident, $b:ident, $t:expr, $f:expr) => {{
macro_rules! check_equal {
($a) => { $t };
($b) => { $f };
}
check_equal!($b)
}};
}
@tjjfvi
tjjfvi / ts-utils.md
Last active May 1, 2022 15:26
A collection of utilities for programming in TypeScript's Type System

This is a collection of utilities for programming in TypeScript's Type System.

Each codeblock represents one utility type, but there are often multiple implementations. Each implementation has equivalent semantics, but differ in dependency count and length.

Most of the time, the implementation you pick should not really matter.

However, if you are code-golfing, alternate versions may be better or worse depending on what other utility types you need. Also, some implementations may benefit from inlining.

@tjjfvi
tjjfvi / ts-types-lambda-calc.ts
Last active February 17, 2024 21:03
Lambda Calculus in TypeScript Types: https://tsplay.dev/wE5nZw
type _I = Reduce<[S, K, K]>
// ^?
type One = I
type Zero = Reduce<[K, I]>
// ^?
type Add = { a: { b: { i: { z: ["a", "i", ["b", "i", "z"]] } } } }
type Mul = { a: { b: { i: ["a", ["b", "i"]] } } }
type Two = [Add, One, One]
type Three = [Add, Two, One]
type Six = [Add, Three, Two]
@tjjfvi
tjjfvi / honeypot.txt
Created February 21, 2021 01:20
TS Discord Honeypot
<#740267971422715989> ```
_____ _______ ____ _____ _
/ ____|__ __/ __ \| __ \ _ | | _
| (___ | | | | | | |__) (_) __ _ ___ | |_ ___(_)
\___ \ | | | | | | ___/ / _` |/ _ \ | __/ _ \
____) | | | | |__| | | _ | (_| | (_) | | || (_) |
|_____/ |_| \____/|_| ( ) \__, |\___/ \__\___(_)
|/ __/ |
_ _ ___ _ |___/ _ _ _ _
_| || |_ |__ \ | | | | | | | | | |
@tjjfvi
tjjfvi / callableClass.flow.js
Last active March 2, 2020 22:49
Create a callable class in Flow
const _Name = { Name: class <T> {
val: T;
constructor(val: T){
this.val = val;
}
} }.Name;
const Name = (() => {
declare class Name<T> extends _Name<T> {