Skip to content

Instantly share code, notes, and snippets.

View LeeeeT's full-sized avatar
😎
😎

LeeeeT

😎
😎
View GitHub Profile
from collections.abc import Callable
from dataclasses import dataclass
from itertools import count
from typing import Any
type Name = int
name = count(0)
from dataclasses import dataclass
from itertools import count
type Name = int
name = count(0)
@LeeeeT
LeeeeT / .py
Last active July 7, 2025 14:30
HOAS CoC
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any
type Term[T] = Var[T] | Typ[T] | Lam[T] | Fun[T] | App[T]
@dataclass(frozen=True)
class Var[T]:
@LeeeeT
LeeeeT / list.py
Last active June 20, 2025 21:44
Inductive and coinductive definitions of list
# Algebra f a = f a β†’ a
# Fix f = βˆ€x. Algebra f x β†’ x
# Coalgebra f a = a β†’ f a
# Cofix f = βˆƒx. x Γ— Coalgebra f x
# ListF a x = 1 + a Γ— x
# List a = Fix (ListF a)
# Colist a = Cofix (ListF a)
@LeeeeT
LeeeeT / README.md
Last active July 26, 2025 18:23
Purer IO (probably works too)

This script simulates IO (print and input) in a pure functional manner using a coinductive data structure.


Python-compatible generator:

Generator yield send return = βˆƒstate . state Γ— (state β†’ return + yield Γ— (send β†’ state))

With the point functor:

P ⊒ Q
----- β†’-Intro
P β†’ Q
P β†’ Q P
-------------- β†’-Elim
Q
@LeeeeT
LeeeeT / felis.py
Last active March 16, 2025 11:25
top 5 sins
from __future__ import annotations
import asyncio
from collections.abc import Callable
from dataclasses import dataclass
from typing import Protocol
import felis
@LeeeeT
LeeeeT / inet.py
Last active August 12, 2025 14:22
from __future__ import annotations
import itertools
import sys
from collections import Counter, defaultdict
from dataclasses import dataclass
@LeeeeT
LeeeeT / ic.py
Last active February 12, 2025 19:54
Interaction Combinators (39% ugly)
import itertools
port = itertools.count()
wires = dict[int, int]()
cells = dict[int, tuple[str, int, tuple[int, ...]]]()
queue = set[tuple[int, int]]()
@LeeeeT
LeeeeT / pythags.py
Last active August 30, 2024 17:37
Finding pythagorean triples ("I hate my life" edition)
from sys import setrecursionlimit
setrecursionlimit(10000)
lift2 = lambda identity: lambda apply: lambda function: lambda first: apply(apply(identity(function))(first))
bind = lambda map: lambda join: lambda value: lambda function: join(map(function)(value))