Skip to content

Instantly share code, notes, and snippets.

type msg = ..
type query_answer =
| Accepted
| Unknown
let printer_registry: (Format.formatter -> msg -> query_answer) list ref = ref []
let register_printer x = printer_registry := x :: !printer_registry
let print ppf msg =
type 'a s = private Succ
type ('elt,'size) t =
| [] : ('elt, 'a -> 'a) t
| (::): 'elt * ('elt, 'z -> 'k) t -> ('elt, 'z -> 'k s) t
let rec (@): type elt low mid high.
(elt, mid -> high) t -> (elt, low -> mid) t -> (elt, low -> high) t =
fun l r ->
match l with
type void = |
module Make(T:sig type 'a t end) = struct
type 'a t =
| []: void t
| (::): 'a T.t * 'b t -> ('a -> 'b) t
end
module HL = Make(struct type 'a t = 'a end)
module Config: sig
type mode
type onhist
class type uioh = object end
type keyhash
type onkey
type ondone
type cancelonempty
type onleave
type infochange
module type T = sig
type t
val x: t
val show: t -> string
end
module Int = struct
type t = int
let x = 1
let show = string_of_int
type 'a term =
| Var of 'a
| App of 'a term * 'a term
let rec pp pp_elt ppf = function
| Var x -> pp_elt ppf x
| App(f,x) ->
Format.fprintf ppf "%a(%a)" (pp pp_elt) f (pp pp_elt) x
@Octachron
Octachron / hide_your_type.ml
Created March 19, 2021 07:52
How to temporarily hide a type
type _ foo = F1: int foo | F2: boo foo
type 'b any = Any: 'a foo * ('a,'b) eq -> 'b any
let split x = Any(x,Refl)
let g (type tmp) (): int =
let Any (type t) (foo,secret: t foo * (t,_) eq ) = split F1 in
let tmp: t = match foo with F1 -> 0 | F2 -> true in
match secret with Refl -> tmp
module M = Map.Make(struct type t = int let compare = compare end)
type _ maps =
| Int: int M.t maps
| Float: float M.t maps
let add_zero_int (w:int M.t maps) = match w with
| Int -> 0
| _ -> .
(* TEST
* bytecode
ocamlc_byte_exit_status = "2"
*)
[@@@warning "@8"]
let None = None
module type empty = sig end
module Empty = struct end;;
module type a
module type b
module type c
module Example_2 = struct
module type f = functor (X:a)(Y:b) -> c