Skip to content

Commit

Permalink
✨ add combinator spellings; #34
Browse files Browse the repository at this point in the history
  • Loading branch information
codereport committed Mar 13, 2024
1 parent 90b9bbb commit 163be46
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/arity_notation.py
Expand Up @@ -8,19 +8,19 @@
from prompt_toolkit.shortcuts import CompleteStyle

combinators = {
"W": ["1y2", "fn w(f) = x -> f(x,x)" , None],
"C": ["2y2", "fn c(f) = x,y -> f(y,x)" , None],
"B": ["1y11", "fn b(f,g) = x -> f(g(x))" , None],
"B₁": ["2y12", "fn b₁(f,g) = x,y -> f(g(x,y))" , None],
"S": ["1y21", "fn s(f,g) = x -> f(x,g(x))" , None],
"Σ": ["1y12", "fn Σ(f,g) = x -> f(g(x),x)" , None],
"D": ["2y21", "fn d(f,g) = x,y -> f(x,g(y))" , None],
"Δ": ["2y12", "fn Δ(f,g) = x,y -> f(g(x),y)" , None],
"Ψ": ["2y21", "fn Ψ(f,g) = x,y -> f(g(x),g(y))" , None],
"Φ": ["1y121", "fn Φ(f,g,h) = x -> g(f(x),h(x))" , None],
"D₂": ["2y121", "fn d₂(f,g,h) = x,y -> g(f(x),h(y))" , "l f : g : r h"],
"Φ.₂": ["2y122", "fn Φ.₂(f,g,h) = x,y -> g(f(x),h(x,y))" , None],
"Φ₁": ["2y222", "fn Φ₁(f,g,h) = x,y -> g(f(x,y),h(x,y))", None],
"W": ["1y2", "fn w(f) = x -> f(x,x)" , "f₁ w", "f₁"],
"C": ["2y2", "fn c(f) = x,y -> f(y,x)" , "-", "f₂ c"],
"B": ["1y11", "fn b(f,g) = x -> g(f(x))" , "f₁ g₁", "f₁ g₁"],
"B₁": ["2y21", "fn b₁(f,g) = x,y -> g(f(x,y))" , "-", "f₂ g₁"],
"S": ["1y12", "fn s(f,g) = x -> g(x,f(x))" , "f₁ g₂", "-"],
"Σ": ["1y21", "fn Σ(f,g) = x -> f(g(x),x)" , "f₂ g₁", "-"],
"D": ["2y21", "fn d(f,g) = x,y -> f(x,g(y))" , "-", "l : g₂ : r f₁"],
"Δ": ["2y12", "fn Δ(f,g) = x,y -> f(g(x),y)" , "-", "f₁ g₂"],
"Ψ": ["2y21", "fn Ψ(f,g) = x,y -> g(f(x),f(y))" , "-", "pair f₁ g₂ fold"],
"Φ": ["1y121", "fn Φ(f,g,h) = x -> g(f(x),h(x))" , "f₁ g₂ h₁", "-"],
"D₂": ["2y121", "fn d₂(f,g,h) = x,y -> g(f(x),h(y))" , "-", "l f : g : r h"],
"Φ.₂": ["2y122", "fn Φ.₂(f,g,h) = x,y -> g(f(x),h(x,y))" , "-", "f₁ g₂ h₂"],
"Φ₁": ["2y222", "fn Φ₁(f,g,h) = x,y -> g(f(x,y),h(x,y))", "-", "f₂ g₂ h₂"],
}

def num_to_greek_arity(i: int) -> str:
Expand All @@ -39,14 +39,14 @@ def arity_notation_to_english(an: str, translate) -> str:


def describe(c: str, translate):
[an, f, impl] = combinators[c]
[an, f, m_impl, d_impl] = combinators[c]
draw.cprint(f"\nThe {c} Combinator:\n", Fore.GREEN, True)
print(f"The {c} combinator {arity_notation_to_english(an, translate)}")
print("A sample implementation could be the following:")
draw.cprint(f"\n {f}\n", Fore.YELLOW, True)
if impl:
print("You can spell this in Jello as follows:")
draw.cprint(f"\n {impl}\n", Fore.CYAN, True)
print("You can spell this in Jello as follows:")
draw.cprint(f"\n Monadic: {m_impl}", Fore.CYAN, True)
draw.cprint(f" Dyadic: {d_impl}\n", Fore.CYAN, True)

def explain():

Expand All @@ -61,9 +61,10 @@ def explain():
describe(user_input, f)
elif user_input == "All":
print()
for c, [_, fn, impl] in combinators.items():
print(f"{' ' * 46}|{'Monadic':^10}|{'Dyadic':^18}|")
for c, [_, fn, m_impl, d_impl] in combinators.items():
[x, _, y, _, z] = utils.split_keep_multiple_delimiters(fn, ["=", "->"])
print(f"{c:<4} {x:<14}={y:<5}->{z:18}{'Spelling: ' + impl if impl else ''}")
print(f"{c:<4} {x:<14}={y:<5}->{z:18} |{m_impl:^10}|{d_impl:^18}|")
print()
else:
draw.cprint(" did not enter a valid combinator", Fore.RED, True)

0 comments on commit 163be46

Please sign in to comment.