Created
January 1, 2022 07:17
-
-
Save asukaminato0721/43c88ebe647039428862861630fee690 to your computer and use it in GitHub Desktop.
https://youtu.be/7oV7hiAsVTI?t=1272 py version
This file contains 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
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