Skip to content

Instantly share code, notes, and snippets.

type poly = Wrap : 'a key * 'a value -> poly
let rec map f = function
| Nil -> Nil
| Cons (k, v, rest) ->
let Wrap (k', v') = f.f k v in
Cons (k', v', map f rest)
type (_, _) eq =
| Eq : ('a, 'a) eq
| NEq : (_, _) eq
module type Eq = sig
type 'a key
type 'a value
val eq : 'a key -> 'b key -> ('a, 'b) eq
end
type (_, _) eq =
| Eq : ('a, 'a) eq
| NEq : (_, _) eq
module type Eq = sig
type 'a key
type 'a value
val eq : 'a key -> 'b key -> ('a, 'b) eq
end
type (_, _) eq =
| Eq : ('a, 'a) eq
| NEq : (_, _) eq
module type Eq = sig
type 'a key
type 'a value
val eq : 'a key -> 'b key -> ('a, 'b) eq
end
type id = string
module IdMap = Map.Make (String)
type ('a, 'b) alt = Left of 'a | Right of 'b
module TypeTerm = struct
type t =
| Unit | Bool | Int
| Pair of t * t
@gsg
gsg / test.ml
Created February 26, 2016 17:30
let r : int option ref = ref None
let test = Lazy.from_fun (fun () -> match !r with
| None -> assert false
| Some x -> x)
let _ = r := Some 42
let _ = print_int (Lazy.force test)
let _ =
(*
* Construct a string comprising two words (and a header, which
* we shall ignore). The bytes are laid out like this:
*
* char: a b c d \0 \0 \0 03
* hex: 61 62 63 64 . 00 00 00 03
*)
let str = "abcd" in
@gsg
gsg / test.ml
Created December 11, 2015 13:14
type abc = [`A | `B | `C]
let f (x:abc) = 0
let needs_coercing : [< `A | `B] = `A
(* Type error *)
let _ = f needs_coercing
(* OK *)
@gsg
gsg / test.ml
Created December 7, 2015 16:08
type _ t =
| Bool : bool t
| Int : int t
let x = object (self)
method f : type a . a t -> a t = function
| Bool -> Bool
| Int -> (self#int Int : int t)
method int Int = Int
@gsg
gsg / test.ml
Created November 27, 2015 13:58
module rec A : sig
type t = X of ASet.t | Y
val compare : t -> t -> int
end = struct
type t = X of ASet.t | Y
let compare = Pervasives.compare
end
and ASet : Set.S with type elt = A.t = Set.Make(A)