Skip to content

Instantly share code, notes, and snippets.

View LeeeeT's full-sized avatar
😎
😎

LeeeeT

😎
😎
View GitHub Profile
@LeeeeT
LeeeeT / io.py
Last active December 15, 2025 15:53
Inductive free IO monad
# Map f = (a -> b) -> f a -> f b
# Id f = a -> f a
# Join f = f (f a) -> f a
# Bind f = f a -> (a -> f b) -> f b
# Then f = f a -> f b -> f b
@LeeeeT
LeeeeT / io.py
Last active November 30, 2025 22:01
IO (inductive Free)
# Map f = (a -> b) -> f a -> f b
# Id f = a -> f a
# Join f = f (f a) -> f a
# Bind f = f a -> (a -> f b) -> f b
# TakeAfter f = f a -> f b -> f b
@LeeeeT
LeeeeT / itt.py
Last active October 29, 2025 17:43
(Broken)
from dataclasses import dataclass
from itertools import count
type Name = int
name = count()
@LeeeeT
LeeeeT / Ξ».py
Last active July 31, 2025 14:41
Attempt number [NaN]
from dataclasses import dataclass
from itertools import count
type Name = int
name = count()
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