Skip to content

Instantly share code, notes, and snippets.

View Nymphium's full-sized avatar
⚜️
百合

Nymphium Nymphium

⚜️
百合
View GitHub Profile
(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))
命令列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
@Nymphium
Nymphium / yh.tex
Last active December 30, 2019 19:45
% 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}
(*
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
@Nymphium
Nymphium / embedding_with_free.lua
Created October 8, 2019 06:43
embedding algebraic effects with free (but untyped)
-- 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
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>
@Nymphium
Nymphium / cont.kk
Last active September 8, 2019 21:09
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
}
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"));
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
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