environment | |
---|---|
OS | ArchLinux |
Mem | 16GB |
CPU | intel Core i7 8565U |
$ time node hoge
hello
!
[@@@alert "-unstable"] | |
[@@@warning "-32"] | |
(* Reimplementation of Go's worker pools using Eio and Domainslib.Chan | |
https://gobyexample.com/worker-pools | |
*) | |
module Stdenv = struct | |
type _ Effect.t += Get : (Eio.Stdenv.t * Eio.Switch.t) Effect.t |
type (_, _) operation = .. | |
type 'a computation = | |
| Return : 'a -> 'a computation | |
| Call : ('arg, 'res) operation * 'arg * ('res -> 'a computation) -> 'a computation | |
type ('a, 'b) handler = { | |
return : 'a -> 'b computation; | |
operations : 'arg 'res. ('arg, 'res) operation -> | |
'arg -> ('res -> 'b computation) -> 'b computation |
interface Get { | |
readonly _tag: 'Get'; | |
readonly _ans: number; | |
} | |
interface Put { | |
readonly _tag: 'Put'; | |
readonly _ans: void; | |
value: number; | |
} |
type (_, _) cont = | |
Cont : (('a -> 'r) -> 'r) -> ('r, 'a) cont | |
let runCont : ('r, 'a) cont -> ('a -> 'r) -> 'r | |
= fun (Cont f) k -> f k | |
let runCont' k cf = runCont cf k | |
let return x = Cont((|>) x) |
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 typed-delimcc | |
public effect subcont0<a> { | |
fun shift0(f : (b -> a) -> a) : b | |
} | |
public fun reset0(th : () -> subcont0<a> a) : a { | |
handle(th) { | |
shift0(f) -> f(resume) | |
} |
module type NATURAL = sig | |
type t | |
val build : ((t -> t) -> t -> t) -> t | |
end | |
module type BUILD_NATURAL = functor | |
(M : sig | |
type t |
module Base = struct | |
type _ operations = .. | |
end | |
module Freer : sig | |
type _ t | |
module Syntax : sig | |
val ( let* ) : 'a t -> ('a -> 'b t) -> 'b t | |
end |
module type S = sig val x: int end | |
let module M = struct let x = 3 end in | |
Obj.magic (module M : S) |> fun m -> let module M = (val m : S) in M.x (* 3 *) |
environment | |
---|---|
OS | ArchLinux |
Mem | 16GB |
CPU | intel Core i7 8565U |
$ time node hoge
hello
!