I'm going to make the following simplifying assumptions:
-
There aren't many custom_alloc_custom_mem blocks (caml_dependent_size ~= 0)
-
There aren't many caml_alloc_custom blocks with nonzero mem/max
# type t = Foo;; | |
type t = Foo | |
# type r = { foo : t };; | |
type r = { foo : t; } | |
# let x : r = { foo = Foo } ;; | |
val x : r = {foo = Foo} | |
# type s = t = private Foo;; | |
type s = t = private Foo | |
# let x : r = { foo = Foo } ;; | |
Error: Cannot create values of the private type s |
type t = { | |
mutable a : int option; | |
mutable b : float; | |
mutable c : float; | |
mutable d : float; | |
mutable e : float; | |
mutable f : float; | |
} | |
let make_arr () = |
type tree = | |
| Leaf of { mutable x : int } | |
| Br2 of tree * tree | |
| Br5 of tree * tree * tree * tree * tree | |
let rec mk = function | |
| n when n <= 0 -> Leaf { x = 0 } | |
| n when n mod 3 = 0 -> Br2 (mk (n - 1), mk (n - 1)) | |
| n -> Br5 (mk (n-1), mk (n-2), mk (n-3), mk (n-4), mk (n-5)) |
type pair32 = { mutable left : #int32; mutable right: #int32 } | |
external box32 : #int32 -> int32 = "%identity" | |
external unbox32 : int32 -> #int32 = "%identity" | |
let incr_left x = | |
x.left <- unbox32 (Int32.add (box32 x.left) 1l) |
external unsafe_set_imm : ('a : immediate) . 'a array -> int -> 'a -> unit = "%array_unsafe_set" | |
type ('a : value) is_immediate = | |
| Immediate : ('b : immediate) . 'b is_immediate | |
| Value : 'a is_immediate | |
let fill (type a) (e : a is_immediate) (arr : a array) (x : a) = | |
match e with | |
| Immediate -> | |
for i = 0 to Array.length arr - 1 do |
(require 'quail) | |
(setf mathematical-symbol-table '( | |
("&&" ?∩ "\\cap") | |
("&&" ?∧ "\\land") | |
("&&" ?⊓ "\\sqcap") | |
("&&n" ?⋂ "\\bigcap") | |
("&&n" ?⋀ "\\bigland") | |
("&&n" ?⨅ "\\bigsqcap") | |
("||" ?∪ "\\cup") | |
("||" ?∨ "\\lor") |
module Int64Array : sig | |
module Array : sig | |
type t | |
val create_uninitialised : int -> t | |
val get : t -> int -> int64 | |
val set : t -> int -> int64 -> unit | |
val unsafe_get : t -> int -> int64 | |
val unsafe_set : t -> int -> int64 -> unit | |
end | |
end = struct |
(* See https://dornsifecms.usc.edu/assets/sites/520/docs/VonNeumann-ams12p36-38.pdf *) | |
let u () = Random.float 1. | |
let rec exp () = | |
let x = u () and y = u () in | |
if f x y then x else exp () +. 1. | |
and f x y = x < y || g (u ()) y | |
and g x y = x < y && f x (u ()) |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
static uint32_t mulhi(uint32_t a, uint32_t b) { | |
return (uint32_t)(((uint64_t)a * (uint64_t)b) >> 32); | |
} | |
// x in (0, 1). computes an approximation of -log2(x) |