Skip to content

Instantly share code, notes, and snippets.

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 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)
(* TEST
flags = "-I ${ocamlsrcdir}/parsing"
include ocamlcommon
* expect
*)
let x = Ast_helper.Exp.ident
[%%expect{|
val x :
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)
type visited = Visited
type free = Free
type vi = visited
type e = |
type 'a chess = 'a
constraint
'a =
<
ul: _; up: _; ur: _;
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
--- /dev/null
+++ b/contents_motif.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <path fill="none" d="M0 0h24v24H0V0z"/>
+ <path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/>
+</svg>
diff --git a/cut.mli b/cut.mli
index e99562c..37d7a56 100755
--- a/cut.mli
module X: sig
type +'a t
val one: [`one of _ ] t
val two: [`two of _ ] t
val match':
[< `one of 'r & 'a | `two of 'r & 'b] t -> 'a -> 'b -> 'r
end = struct
type 'a t = One | Two
let one = One
let two = Two
type scalar = float
type 'a one = [`one of 'a]
type 'a z = [`zero of 'a]
type 'a two = [`two of 'a]
type 'a three = [`three of 'a]
type 'a four = [`three of 'a]
let map2 f x y = Array.init (min (Array.length x) (Array.length y))
(fun n -> f x.(n) y.(n))
type scalar = float
type z = private Z type 'a s = private S
type _ t =
| Scalar: scalar -> 'any t
| Vec2: {x:float;y:float} -> z s t
| Vec3: {x:float;y:float;z:float} -> z s s t
let (+) (type dim) (x: dim t) (y:dim t) : dim t =
match x, y with
| Scalar a, Scalar b -> Scalar (a +. b)