Skip to content

Instantly share code, notes, and snippets.

type (_,_) nuple =
| Z : (unit,unit) nuple
| P: ('a * ('b,'c) nuple) -> ('a, ('b,'c) nuple ) nuple
let p=P(1, P("try", P( [4,5], Z)))
let rec map: 'a 'b 'c 'd 'e 'f. ('a,'b) nuple -> ('c,'d) nuple ->('e,'f) nuple=
fun fs ps -> match (fs,ps ) with
let pp = Printf.printf
module Explanation = struct
pp "At the begining of a module (or the beginning of the file),";
pp "we start in execution mode\n.";
pp "We can have a" ;
pp "comma separated list of expression which is evaluted";
pp "at the top-level of the module.\n"
open List [@@remark "This is not an expression: we exit evalation mode" ]
module K = struct
let ( * ) = ( *. )
let ( + ) = ( +. )
let ( / ) = ( /. )
let ( - ) = ( -. )
let ( ~- ) = ( ~-. )
end
module V = struct
let zero = 0., 0., 0.
type nil
(* heteregenous list with no concatenation *)
type 'list t =
| Nil: nil t
| Cons: 'a * 'b t -> ('a -> 'b) t
(* concatenation helper *)
type (_,_, _ ) helper =
| Z : ( nil , 'e, 'e) helper
| S: ('a,'b, 'e) helper -> ('c -> 'a, 'c -> 'b, 'e) helper
let d = 3
let m = 1000
let replicate_with_failures k rng st =
let rec aux l k =
if k = 0 then l else
match rng st with
| Some x -> aux (x::l) (k-1)
| None -> aux l (k-1) in
module Natl =struct
type z = Nil_z
type 'a succ = Nil_succ
end
open Natl
type _ t =
| Nil: <f:'a; t:'a; dim:z > t
| Cons:
'elt * <f:'ty; t:'ret; dim:'d > t -> <f: 'elt -> 'ty; t:'ret; dim:'d succ> t
module N : sig
type +'a t = private int
val create : int -> 'a t
end= struct
type +'a t = int
let create n = n
end
type nil = private Nil_type
(* empty type*)
type void = private Void
(* list type *)
type _ hlist =
| Nil: void hlist
| Cons:
'elt * 'a hlist -> ( 'elt * 'a ) hlist
let rec length: type a. a hlist -> int = function%with_ll
type 'a t =
| Leaf of 'a
| Node of (int -> 'a) t * (int -> 'a) t
let l = Leaf ();;
let f n = n
let g n k = n + k
let n = Node(Leaf f, Leaf f)
module type s = sig
type 'a t
val hash : 'a t -> int
val equal : 'a t -> 'a t -> bool
end
module Id: s = struct
type 'a t = {
id : int;