Skip to content

Instantly share code, notes, and snippets.

View c-cube's full-sized avatar

Simon Cruanes c-cube

View GitHub Profile
@c-cube
c-cube / lambda_calculus.ml
Created October 14, 2016 16:55
simply typed lambda calculus + µ binders
open Format
type tp = Ti | To | Arr of tp * tp
let pp_wrap condition pp_fmt fmt x=
if condition then
fprintf fmt "(%a)" pp_fmt x
else
fprintf fmt "%a" pp_fmt x
@c-cube
c-cube / gen_expr.ml
Last active August 3, 2016 16:11
generate all possible expressions from a list of basic values
(* ocamlfind opt -package sequence,benchmark -linkpkg truc.ml -o truc; ./truc*)
open Sequence.Infix
type op =
| Add
| Mult
| Div
| Minus
@c-cube
c-cube / bench_combs.ml
Created August 3, 2016 15:14
benchmarking various implems of "combinations"
(* ocamlfind opt -package sequence,benchmark -linkpkg truc.ml -o truc; ./truc*)
open Sequence.Infix
(* all the combinations *)
let rec combs = function
| [] -> Sequence.return []
| x :: tail ->
Sequence.append (combs tail) (combs tail >|= fun l -> x :: l)
@c-cube
c-cube / combinations.ml
Last active August 3, 2016 15:14
combinations of a list with Sequence
#require "sequence";;
open Sequence.Infix;;
(* all the combinations *)
let rec combs = function
| [] -> Sequence.return []
| x :: tail ->
Sequence.append (combs tail) (combs tail >|= fun l -> x :: l);;
@c-cube
c-cube / perms.ml
Last active August 3, 2016 14:18
permutations using Sequence
#require "sequence";;
open Sequence.Infix;;
let rec perms = function
| [] -> Sequence.return []
| x :: tail -> perms tail >>= insert x
and insert x l = match l with
| [] -> Sequence.return [x]
(* ocamlfind opt -g -package zarith -package containers.iter -linkpkg primes.ml -o primes *)
module L = CCLazy_list;;
let gen_int =
let n = ref Z.one in
fun () ->
let x = !n in
n := Z.succ !n;
Some x
@c-cube
c-cube / bench.ml
Last active April 21, 2016 12:52
small benchmark (requires: gen, sequence, benchmark)
module G = struct
type 'a t = unit -> 'a option
let (--) i j =
let r = ref i in
fun () ->
if !r > j then None
else (let x = !r in incr r; Some x)
@c-cube
c-cube / test.md
Last active September 22, 2015 07:54
tests for github markdown

|

a | b c | d

@c-cube
c-cube / qtest.adoc
Last active September 15, 2015 17:05

QTest

@c-cube
c-cube / ty.ml
Last active August 29, 2015 14:25
small `'a ty` implementation
type 'a hlist =
| HNil : unit hlist
| HCons : 'a * 'b hlist -> ('a * 'b) hlist
(** Description of type ['a] *)
type 'a ty =
| Int : int ty
| Bool : bool ty
| Sum : 's sum -> 's ty