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
(require control/racket) | |
; (% (+ (fcontrol 3) (fcontrol 4)) (λ (x k) (k (* x x)))) | |
; ~> ((λ (x k) (k (* x x))) 3 (λ (y) (+ y (fcontrol 4)))) | |
; ~> ((λ (y) (+ y (fcontrol 4))) 9) | |
; ~> (+ 9 (fcontrol 4)) | |
; ~> %の外側に出ちゃたあ(正しい) | |
(let [(p (make-continuation-prompt-tag))] | |
(% (+ (fcontrol 3 #:tag p) (fcontrol 4 #:tag p)) (λ (x k) (k (* x x))) #:tag p)) |
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
命令列Cと状態{m, h, w, d, p}の遷移から成るPainter Programmingの小ステップ意味論を考える。 | |
要素が{0, 1}から成るHxW行列が得られる。 | |
`M`atrix, `H`eight, `W`idth, `D`irection[←↓↑→], `P`rogram stack | |
init = { m = H x Wの000...0, h = 1, w = 1, d = →, P = []} | |
## 補助関数 | |
edge_HW → H _ = true | |
edge_HW ← 1 _ = true |
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
% lualatex main.tex | |
% convert -density 2000 -strip main.pdf out.png | |
\documentclass[tikz]{standalone} | |
\usepackage{graphicx} | |
\usepackage{pagecolor,xcolor} | |
\usepackage{newtxmath} | |
% \usepackage{pagecolor} | |
% \definecolor{greenback}{HTML}{00ff00} | |
% \pagecolor{greenback} |
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
(* | |
ref: Efficient Compilation of algebraic effects and handlers | |
*) | |
type (_, _) operation = .. | |
type 'a computation = | |
| Return : 'a -> 'a computation | |
| Call : ('arg, 'res) operation * 'arg * ('res -> 'a computation) -> 'a computation |
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
-- allocate variable for back patching | |
local bind | |
-- type computation | |
local computation = function(t) | |
return function(a) | |
return setmetatable(a, { __index = t, __shr = bind }) | |
end | |
end |
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
public module ext/error | |
struct error1(reason: string) | |
struct error2(param: int) | |
effect httpError<e> { | |
fun httpError(: e, v: int) : e | |
} | |
val handle_error : forall<e, u> |
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
public module cont | |
public import function | |
public struct ccont<r, a>(k : (a -> r) -> r) | |
public fun runCont<r, a>(c : ccont<r, a>): ((a -> r) -> r) { | |
c.k | |
} |
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
const Read = (key) => ({type : 'Read', arguments : [ key ]}); | |
const Write = (key, value) => ({type : 'Write', arguments : [ key, value ]}); | |
const performWith = (handler, eff) => | |
new Promise(() => { throw eff; }).catch(handler); | |
async function go(handler) { | |
const x = await performWith(handler, Read("x")); | |
await performWith(handler, Write("z", x + 4)); | |
const z = await performWith(handler, Read("z")); |
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
module type GEN = functor(T : sig type arg type ans end) -> sig | |
val genrec : ((T.arg -> T.ans) -> T.arg -> T.ans) -> T.arg -> T.ans | |
end | |
module Gen : GEN = functor(T : sig type arg type ans end) -> struct | |
open T | |
effect Call_self : arg -> ans | |
let genrec (fn : (arg -> ans) -> arg -> ans) (a : arg) = | |
let filled a' = fn (fun arg -> perform (Call_self arg)) a' in |
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
effect Id : 'a -> 'a;; | |
let handler th = | |
match th () with | |
| x -> x | |
| effect (Id v) k -> continue k v;; | |
let handler' th = | |
match th () with | |
| x -> x |