Hazel reports · ^report(46) · the Witch's picture · one page per output · updated 2026-11-08 08:03 MST
The Witch's picture view: js_of_ocaml 5.9.1's output
One of six pages, one per version of the Witch slide's ^picture view (^report(46), a view): Hazel · hazel-jit's output · ReScript 12.3.1's output · Melange 5.0.0's output · js_of_ocaml 5.9.1's output · JavaScript by hand.
js_of_ocaml compiles the whole program, OCaml's runtime with it (115 KB here), and renames everything. The view is _dv_: framing, bounds and grow_all inlined into it as nested for loops, every tuple an array with its tag first. Each number is _dc_, OCaml's Printf.sprintf "%.1f", which interprets the format at run time before it calls toFixed: 1.01 ms against 0.19 ms when fixed1 calls JS's toFixed instead (witch-jsoo-tofixed.ml).
OCaml source (witch-jsoo.ml, without the picture's literal and the timing loop)
(* for js_of_ocaml: a number formatted as OCaml formats one *) let fixed1 (x : float) = Printf.sprintf "%.1f" x (* the picture, as the slide's types *) type point = float * float type label = Plain | Anchor of string type vertex = { at : point; label : label } type stroke = { width : float; color : string } type shape = | Polygon of { name : string; points : vertex list; stroke : stroke; fill : string } | Path of { name : string; points : vertex list; stroke : stroke } type picture = shape list (* what a view returns: Hazel's Html and Attr, as far as this view uses them *) type attr = Create of string * string | Width of string | Height of string | Style of (string * string) list type html = Node of string * attr list * html list | Div of attr list * html list | Text of string (* the view *) let num (x : float) = fixed1 x let rec coords (vs : vertex list) = match vs with | [] -> "" | v :: tl -> let (x, y) = v.at in fixed1 x ^ "," ^ fixed1 y ^ " " ^ coords tl let shape_node (s : shape) = match s with | Polygon p -> Node ("polygon", [ Create ("points", coords p.points); Create ("fill", p.fill); Create ("stroke", p.stroke.color); Create ("stroke-width", num p.stroke.width); Create ("stroke-linejoin", "round") ], []) | Path p -> Node ("polyline", [ Create ("points", coords p.points); Create ("fill", "none"); Create ("stroke", p.stroke.color); Create ("stroke-width", num p.stroke.width); Create ("stroke-linejoin", "round"); Create ("stroke-linecap", "round") ], []) let rec shape_nodes (ss : picture) = match ss with [] -> [] | s :: tl -> shape_node s :: shape_nodes tl let vertices_of (s : shape) = match s with Polygon p -> p.points | Path p -> p.points let grow ((x0, y0, x1, y1) : float * float * float * float) (v : vertex) = let (x, y) = v.at in ((if x -. 12. < x0 then x -. 12. else x0), (if y -. 12. < y0 then y -. 12. else y0), (if x +. 12. > x1 then x +. 12. else x1), (if y +. 12. > y1 then y +. 12. else y1)) let rec grow_all b (vs : vertex list) = match vs with [] -> b | v :: tl -> grow_all (grow b v) tl let rec bounds b (ss : picture) = match ss with [] -> b | s :: tl -> bounds (grow_all b (vertices_of s)) tl let rec framing (ss : picture) = match ss with | [] -> [] | s :: tl -> (match s with Path p -> if p.name = "frame" then [ s ] else framing tl | _ -> framing tl) let view_box (pic : picture) = let boxed = match framing pic with [] -> pic | f -> f in let start = match boxed with | [] -> (0., 0., 0., 0.) | s :: _ -> (match vertices_of s with [] -> (0., 0., 0., 0.) | v :: _ -> let (x, y) = v.at in (x, y, x, y)) in let (x0, y0, x1, y1) = bounds start boxed in let (w, h) = (x1 -. x0, y1 -. y0) in let (w2, h2) = if w *. 440. > h *. 320. then (w, w *. 440. /. 320.) else (h *. 320. /. 440., h) in num (x0 -. (w2 -. w) /. 2.) ^ " " ^ num (y0 -. (h2 -. h) /. 2.) ^ " " ^ num w2 ^ " " ^ num h2 (* the view's work once its splice is evaluated: Hazel's `case r | Some(Val(pic)) => ... | _ => ...` *) let view (r : picture option) = match r with | Some pic -> Node ("svg", [ Create ("viewBox", view_box pic); Width "320"; Height "440"; Style [ ("border", "1px solid #ccc"); ("background", "#fafafa") ] ], shape_nodes pic) | None -> Div ([ Style [ ("font-family", "var(--code-font)"); ("font-size", "0.8em") ] ], [ Text "no picture yet" ]) (* (not timed) a drawing as markup, to compare with hazel-jit's; the picture's strings need no escaping *) let rec join f xs = match xs with [] -> "" | x :: tl -> f x ^ join f tl let rec join_sep f sep xs = match xs with [] -> "" | [ x ] -> f x | x :: tl -> f x ^ sep ^ join_sep f sep tl let attr_markup a = match a with | Create (k, v) -> " " ^ k ^ "=\"" ^ v ^ "\"" | Width v -> " width=\"" ^ v ^ "\"" | Height v -> " height=\"" ^ v ^ "\"" | Style kvs -> " style=\"" ^ join_sep (fun (k, v) -> k ^ ": " ^ v) ";" kvs ^ "\"" let rec markup h = match h with | Node (tag, attrs, kids) -> "<" ^ tag ^ join attr_markup attrs ^ ">" ^ join markup kids ^ "</" ^ tag ^ ">" | Div (attrs, kids) -> markup (Node ("div", attrs, kids)) | Text s -> s
js_of_ocaml 5.9.1's JavaScript, --pretty: the view's constants and functions
_dw_ = [0, [1, "320"], [0, [2, "440"], [0, [3, [0, [0, "border", "1px solid #ccc"], [0, [0, "background", "#fafafa"], 0]]], 0]]], _dx_ = "viewBox", _dy_ = "svg", _dz_ = [1, [0, [3, [0, [0, "font-family", "var(--code-font)"], [0, [0, "font-size", "0.8em"], 0]]], 0], [0, [2, "no picture yet"], 0]], _dt_ = [0, 0., 0., 0., 0.], _du_ = [0, 0., 0., 0., 0.], _dg_ = [0, [0, cst_stroke_linejoin, cst_round], 0], _dh_ = cst_stroke_width, _di_ = cst_stroke, _dj_ = cst_fill, _dk_ = cst_points, _dl_ = "polygon", _dm_ = [0, [0, cst_stroke_linejoin, cst_round], [0, [0, "stroke-linecap", cst_round], 0]], _dn_ = cst_stroke_width, _do_ = cst_stroke, _dp_ = [0, cst_fill, cst_none], _dq_ = cst_points, _dr_ = "polyline", _dd_ = [0, [8, [0, 0, 0], 0, [0, 1], 0], "%.1f"], _dO_ = [0, [11, '{"label": "jsoo", "median_ms": ', [8, [0, 0, 0], 0, [0, 4], [11, ', "min_ms": ', [8, [0, 0, 0], 0, [0, 4], [11, ', "chars": ', [4, 0, 0, 0, [11, "}\n", 0]]]]]]], '{"label": "jsoo", "median_ms": %.4f, "min_ms": %.4f, "chars": %d}\n'], _c9_ = caml_obj_tag(_c$_) === 248 ? _c$_ : _c$_[1]; caml_register_named_value("jsError", _c9_); (function(exn){throw exn;}); var _da_ = globalThis; _da_.String; _da_.RegExp; _da_.Object; _da_.Date; _da_.Math; _da_.Error; _da_.JSON; var _db_ = _da_.Array; _c2_ (function(_fd_){ return _fd_[1] === _c__ ? [0, caml_string_of_jsstring(_fd_[2].toString())] : 0; }); _c2_ (function(_fc_){ return _fc_ instanceof _db_ ? 0 : [0, caml_string_of_jsstring(_fc_.toString())]; }); function _dc_(_fb_){return caml_call1(_cx_(_dd_), _fb_);} function _de_(_e9_){ if(! _e9_) return _df_; var _e__ = _e9_[1][1], _fa_ = cst$4 + _de_(_e9_[2]), _e$_ = "," + _dc_(_e__[2]) + _fa_; return _dc_(_e__[1]) + _e$_; } function _ds_(_e4_){ if(_e4_){ var _e5_ = _ds_(_e4_[2]), _e6_ = _e4_[1]; if(0 === _e6_[0]) var _e0_ = [0, [0, _dh_, _dc_(_e6_[3][1])], _dg_], _e1_ = [0, [0, _dj_, _e6_[4]], [0, [0, _di_, _e6_[3][2]], _e0_]], _e7_ = [0, _dl_, [0, [0, _dk_, _de_(_e6_[2])], _e1_], 0]; else var _e2_ = [0, [0, _dn_, _dc_(_e6_[3][1])], _dm_], _e3_ = [0, _dp_, [0, [0, _do_, _e6_[3][2]], _e2_]], _e7_ = [0, _dr_, [0, [0, _dq_, _de_(_e6_[2])], _e3_], 0]; var _e8_ = [0, _e7_, _e5_]; } else var _e8_ = _e4_; return _e8_; } function _dv_(_eU_){ if(! _eU_) return _dz_; var _eV_ = _eU_[1]; a: { b: { var _eE_ = _eV_, _eW_ = _ds_(_eV_); for(;;){ if(! _eE_) break; var _eF_ = _eE_[2], _eG_ = _eE_[1]; if(0 === _eG_[0]) _eE_ = _eF_; else{if(_eG_[1] === cst_frame) break b; _eE_ = _eF_;} } var _eH_ = _eE_; break a; } var _eH_ = [0, _eG_, 0]; } var _eI_ = _eH_ || _eV_; if(_eI_){ var _em_ = _eI_[1][2]; if(_em_) var _eJ_ = _em_[1][1], _eK_ = _eJ_[2], _eL_ = _eJ_[1], _eM_ = [0, _eL_, _eK_, _eL_, _eK_]; else var _eM_ = _dt_; var _eN_ = _eM_; } else var _eN_ = _du_; var _eC_ = _eN_, _eB_ = _eI_; for(;;){ if(! _eB_) break; var _ez_ = _eC_, _ey_ = _eB_[1][2], _eD_ = _eB_[2]; for(;;){ if(! _ey_) break; var _en_ = _ez_[4], _eo_ = _ez_[3], _ep_ = _ez_[2], _eq_ = _ez_[1], _er_ = _ey_[1][1], _es_ = _er_[2], _et_ = _er_[1], _eA_ = _ey_[2], _eu_ = _en_ < _es_ + 12. ? _es_ + 12. : _en_, _ev_ = _eo_ < _et_ + 12. ? _et_ + 12. : _eo_, _ew_ = _es_ - 12. < _ep_ ? _es_ - 12. : _ep_, _ex_ = _et_ - 12. < _eq_ ? _et_ - 12. : _eq_; _ez_ = [0, _ex_, _ew_, _ev_, _eu_]; _ey_ = _eA_; } _eC_ = _ez_; _eB_ = _eD_; } var _eO_ = _eC_[2], _eP_ = _eC_[1], _eQ_ = _eC_[4] - _eO_, _eR_ = _eC_[3] - _eP_; if(_eQ_ * 320. < _eR_ * 440.) var _eT_ = _eR_ * 440. / 320., _eS_ = _eR_; else var _eT_ = _eQ_, _eS_ = _eQ_ * 320. / 440.; var _eZ_ = cst$4 + _dc_(_eT_), _eY_ = cst$4 + _dc_(_eS_) + _eZ_, _eX_ = cst$4 + _dc_(_eO_ - (_eT_ - _eQ_) / 2.) + _eY_; return [0, _dy_, [0, [0, _dx_, _dc_(_eP_ - (_eS_ - _eR_) / 2.) + _eX_], _dw_], _eW_]; }
The files, in 046/data/witch (sources, outputs, the benchmark, the timings): Witch.res, Witch.res.js, bench-runs.jsonl, edit-share.json, edit-share.mjs, firefox-answer-probes.json, firefox-answer.json, firefox-before.json, firefox-cuts.json, firefox-edit.json, firefox-noshare.json, firefox-timeline.json, firefox.json, hazeljit-runtime-src.js, hazeljit-witch-pretty.js, hazeljit-witch-src.js, jsoo-excerpt.js, jsoo-runs.jsonl, picture.hz, picture.json, raw-run1.json, raw-run2.json, timings.json, witch-bench.mjs, witch-core.ml, witch-jsoo-tofixed.ml, witch-jsoo.ml, witch-melange.js, witch-melange.ml.