Skip to content

Instantly share code, notes, and snippets.

from __future__ import annotations
import itertools
import sys
from collections import Counter, defaultdict
from dataclasses import dataclass
@LeeeeT
LeeeeT / λ.py
Last active March 2, 2025 17:05
Clean (in Uncle Bob's voice) implementation of λ-calculus (doesn't work)
from dataclasses import dataclass
program = r"""
(define ->
define (nil -> cons ->
nil
)(nil ->
@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))

Keybase proof

I hereby claim:

  • I am leeeet on github.
  • I am leeeet (https://keybase.io/leeeet) on keybase.
  • I have a public key ASDYtFndK00PVisAWXuWqSJ5PFdRdEhVGog6z-RPDfQ15wo

To claim this, I am signing this object:

@LeeeeT
LeeeeT / scott.py
Created May 28, 2024 19:20
Scott encoding maxed out
from __future__ import annotations
import builtins
from typing import Protocol
class Ty[T]:
pass
@LeeeeT
LeeeeT / sort.py
Last active April 28, 2024 09:56
from collections.abc import Callable
from dataclasses import dataclass
from typing import Protocol, Self
def curry[First, *Rest, Result](
function: Callable[[First, *Rest], Result],
) -> Callable[[*Rest], Callable[[First], Result]]:
return lambda *rest: lambda first: function(first, *rest)
@LeeeeT
LeeeeT / async_option.py
Last active April 8, 2024 18:37
Async-Option monad composition revised
import asyncio
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from typing import Any
def curry[First, *Rest, Result](function: Callable[[First, *Rest], Result]) -> Callable[[*Rest], Callable[[First], Result]]:
return lambda *rest: lambda first: function(first, *rest)
@LeeeeT
LeeeeT / io.py
Last active March 2, 2024 22:12
Pure IO (does work)
import sys
from collections.abc import Callable, Iterator
from functools import cache
type Lazy[T] = Callable[[], T]
type Stream[T] = Lazy[tuple[T, Stream[T]]]
@LeeeeT
LeeeeT / io.py
Created February 25, 2024 12:34
Pure IO
import sys
from collections.abc import Callable, Iterator
from functools import cache
type Lazy[T] = Callable[[], T]
def run_lazy[T](lazy: Lazy[T]) -> T: