Skip to content

Instantly share code, notes, and snippets.

let f [%pattern]: [%type_expression] = [%expression]
module type s = [%module_type]
module M = struct
[%%structure_item]
include [%module_expression]
end
module type S = sig [%%signature_item] end
class c: int -> [%class_type] = fun x -> [%class_expression]
class c: object [%%class_type_field] end = object [%%class_field] end
type visited = Visited
type free = Free
type vi = visited
type e = |
type 'a chess = 'a
constraint
'a =
<
ul: _; up: _; ur: _;
type x = X
type o = O
type 'a l = 'a * 'a * 'a
type 'a c = 'a * 'a * 'a
type 'a s = 'a l c
type 't lfirst = 'a * 'b * 'c
constraint 't = 'a * ('b * 'c)
(* TEST
flags = "-I ${ocamlsrcdir}/parsing"
include ocamlcommon
* expect
*)
let x = Ast_helper.Exp.ident
[%%expect{|
val x :
module type showable = sig
type t
val show: t -> string
end
(** Typeclass emulation *)
let show (type a) (module M: showable with type t = a) x = M.show x
(** Or with a type abbreviation *)
type 'a showable = (module showable with type t = 'a)
opam-version: "2.0"
compiler: [
"base-bigarray.base"
"base-threads.base"
"base-unix.base"
"ocaml.4.05.0"
"ocaml-base-compiler.4.05.0"
"ocaml-config.1"
]
roots: ["ocaml-base-compiler.4.05.0" "ocsigenserver.2.9"]
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
(* TEST
* bytecode
ocamlc_byte_exit_status = "2"
*)
[@@@warning "@8"]
let None = None
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
| _ -> .
@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