Skip to content

Instantly share code, notes, and snippets.

View c-cube's full-sized avatar

Simon Cruanes c-cube

  • https://ahrefs.com/
  • washington DC
  • 04:00 (UTC -04:00)
  • Mastodon @[email protected]
View GitHub Profile
@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 / 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)
(* 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 / 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]
@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 / 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 / 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 / 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 / count_chars.ml
Last active February 2, 2017 21:09
memory map and iterators
#require "bigstring";;
#require "sequence";;
(* the goal is to count how many times each character occurs in the file *)
let file = "foo.txt";;
(* simple way *)
Bigstring.with_map_file file
(fun map ->
@c-cube
c-cube / stdlib_roadmap.md
Last active August 1, 2017 17:48
plans for OCaml's stdlib

Plans for the future of OCaml's stdlib

One of the most common complaint about OCaml, from both newcomers and veterans, is that the stdlib is lacking in several domains. Among these we can list:

  • some modules are absent but should exist (e.g. Option)
  • some modules are present but lack some functionality (e.g. List could have many more combinators)
  • the lack of some transverse features (iterators, printers, monadic operators…)
  • the lack of generality of some constructs. Notably, in_channel