Skip to content

Instantly share code, notes, and snippets.

@aantron
aantron / README.md
Created May 2, 2023 20:05
OCaml runtime value-walking printers

This gist compares the outputs of reason-native's Console.log, Dum, and Inspect's S-expression printer on a test suite that has them print almost every kind of OCaml value.

{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
esy-solve-cudf = stdenv.mkDerivation rec {
name = "esy-solve-cudf-${version}";
version = "0.1.10";
src = fetchurl {
@aantron
aantron / dune
Last active March 15, 2019 06:44
Bisect_ppx+Reason+Dune
(executable
(name foo)
(preprocess (pps bisect_ppx)))
(executable
(name foo)
(libraries bigarray))
@aantron
aantron / html_page.ml
Last active October 4, 2018 17:19
TyXML to Markup.ml
(* Note: `Raw signal is not released. I originally had assert false in the cases that use it. *)
let write_html_to_channel : Pervasives.out_channel -> Tyxml.Html.doc -> unit =
fun channel page ->
let ns name = (Markup.Ns.html, name) in
let convert_attributes attributes =
attributes |> List.map ~f:begin fun attribute ->
let value =
@aantron
aantron / asm-ordinary.s
Last active August 22, 2017 08:46
Code, data for OCaml ordinary and polymorphic variant performance comparison https://discuss.ocaml.org/t/lwt-core-refactored-and-documented-to-be-contributor-friendly/161/28
; Generated from
;
; type ordinary =
; | A | B | C | D
; | E of int | F of int | G of int | H of int
;
; let pattern_match = function
; | A -> 0
; | B -> 1
; | C -> 2
@aantron
aantron / README.md
Created July 23, 2017 14:48
Lwt.pick/Lwt.npick callback ordering

Compile and run the program below with

ocamlfind opt -linkpkg -package lwt.unix foo.ml && ./a.out

As written with Lwt.pick, p2 is canceled first, its callback (registered by Lwt.catch) runs first, and the output is

p2's callback sees p3 pending
@aantron
aantron / lwt.modules.ml
Created May 14, 2017 08:42
The new lwt.ml, with modules folded
(* OCaml promise library
* http://www.ocsigen.org/lwt
* ...
*)
(* Reading guide
... *)
@aantron
aantron / lwt.sigs.ml
Last active May 14, 2017 08:39
The new lwt.ml, with modules folded and signatures expanded
(* OCaml promise library
* http://www.ocsigen.org/lwt
* ...
*)
(* Reading guide
... *)
@aantron
aantron / fragment of java.cpp
Created January 9, 2017 18:09
Java classes inlined into object file, plus loader
// This function calls the JNI routine DefineClass for each class in the
// in-memory class table (see java-classes.h). The class loader parameter passed
// to define class is the result of calling ClassLoader.getSystemClassLoader().
jthrowable java_load_classes()
{
JNIEnv *environment;
jclass class_loader;
jmethodID get_system_loader;
jobject system_loader;
jthrowable exception;