Created
September 16, 2025 19:55
-
-
Save VictorTaelin/8cd1a6bbb689526887d3ab1ccca98c2e to your computer and use it in GitHub Desktop.
enumerating binary trees with 1 label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enumerating Binary Trees with 1 label | |
// ------------------------------------- | |
data Tree { #L #N{a b} } | |
// Recursive: requires label forking | |
@sp0(x) = (+ 0 (* x 2)) | |
@sp1(x) = (+ 1 (* x 2)) | |
@enum(&L) = | |
&L{ | |
#L | |
#N{@enum(@sp0(L)) @enum(@sp1(L))} | |
} | |
@main = @enum(1) | |
// Builder: one label suffices | |
@enum(N T) = | |
~ N !T { | |
0: | |
T | |
1+N: | |
! &1{N0 N1} = N | |
! &1{T0 T1} = T | |
&1{ | |
@enum(N0 (T0 #L)) | |
@enum((+ 2 N1) λx.λy.(T1 #N{x y})) | |
} | |
} | |
@main = @enum(1 λk.k) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment