This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type abc = [`A | `B | `C] | |
let f (x:abc) = 0 | |
let needs_coercing : [< `A | `B] = `A | |
(* Type error *) | |
let _ = f needs_coercing | |
(* OK *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |