Skip to content

Instantly share code, notes, and snippets.

@asukaminato0721
Created January 1, 2022 07:17
Show Gist options
  • Save asukaminato0721/43c88ebe647039428862861630fee690 to your computer and use it in GitHub Desktop.
Save asukaminato0721/43c88ebe647039428862861630fee690 to your computer and use it in GitHub Desktop.
from enum import Enum, auto
from typing import Any, Callable
class msg(Enum):
FIRST = auto()
SECOND = auto()
def cons(x: Any, y: Any):
def dispatch(m: msg):
if m == msg.FIRST:
return x
elif m == msg.SECOND:
return y
else:
raise Exception("Unknown message")
return dispatch
def car(x: Callable[[msg], Any]):
return x(msg.FIRST)
def cdr(x: Callable[[msg], Any]):
return x(msg.SECOND)
print(car(cons(1, 2)))
print(cdr(cons(1, 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment