Created
February 4, 2019 18:04
-
-
Save agumonkey/9955e82373abb42cc2e6d9656bb5a4d2 to your computer and use it in GitHub Desktop.
# ~continuations in python
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: https://www.ps.uni-saarland.de/~duchier/python/continuations.html | |
# more: https://duckduckgo.com/html?q=continuations%20in%20python | |
def sumc(x,y,k): | |
k(x+y) | |
def mulc(x,y,k): | |
k(x*y) | |
def f(x,k): | |
sumc(x,1, lambda i: mulc(i,i,k)) | |
def callcc(f,c): | |
f(c,c) | |
def identity(x): | |
return x | |
def seq(f,g): | |
def seqf(v): | |
f(v) | |
return g(v) | |
return seqf | |
def call(v): | |
def callf(f): | |
return f(v) | |
return callf | |
callcc(lambda k,q: q(seq(print, call)(k)),lambda x: print(42)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment