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 test b x y = | |
match if b then x, y else y, x with | 0, 1 -> 0 | _, _ -> 1 | |
let test2 b x y = | |
let c, d = if b then x, y else y, x in | |
match c, d with | 0, 1 -> 0 | _, _ -> 1 |
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 test = | |
| Int of int | |
| Float of float | |
| Num of Num.num [@printer fun fmt num -> fprintf fmt "%s" (Num.string_of_num num)] | |
[@@deriving show] |
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 arith_op = Add | Sub | Mul | Div | |
type rel_op = And | Or | |
type _ term = | |
| Bool : bool -> bool term | |
| Int : int -> int term | |
| Arith : arith_op * int term * int term -> int term | |
| Rel : rel_op * bool term * bool term -> bool term | |
| If : bool term * 'a term * 'a term -> 'a term |
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 arith_op = Add | Sub | Mul | Div | |
type rel_op = And | Or | |
type _ term = | |
| Bool : bool -> bool term | |
| Int : int -> int term | |
| Arith : arith_op * int term * int term -> int term | |
| Rel : rel_op * bool term * bool term -> bool term | |
| If : bool term * 'a term * 'a term -> 'a term |
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 test x y = | |
let () = () in | |
(fun () -> ignore x; ignore y; ()) | |
(* ggole@Stross:~/src/ocaml❯ ocamlopt -c -dcmm test.ml *) | |
(* (data int 1792 global "camlTest" "camlTest": int 1) *) | |
(* (data *) | |
(* int 4087 *) | |
(* "camlTest__1": *) | |
(* addr "caml_curry2" *) |
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 foo = [`B | `C | `D] | |
let f (x : [`A | foo]) = | |
match x with | |
| `A -> true | |
| #foo as x -> ignore (x :> foo); true |
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 refine x : [`B | `C] option = | |
match x with | |
| `A -> None | |
| (`B | `C) as x -> Some x | |
let f (x : [`A | `B]) = | |
match refine x with | |
| None -> assert false | |
| Some x -> x |
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 test n list = | |
let cons = ref list in | |
for i = 0 to n - 1 do | |
match !cons with | |
| [] -> () | |
| _::xs -> cons := xs | |
done; | |
!cons | |
let test2 observe n list = |
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
(* | |
* Structural equality of objects in OO langauges like Java is | |
* typically implemented using downcasts, guarded by instanceof | |
* checks. The (dynamically checked) downcast provides the | |
* necessary access to the structure of the other object. | |
* | |
* OCaml lacks downcasts, but similar access can be granted in a | |
* typesafe way with equality witnesses. | |
*) |
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 |