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 / python4.md
Last active April 13, 2020 15:12
my totally uninformed opinion on what python4 should be

Python4

We all have in mind the painful transition from python2 to python3. I argue python4 should be a priviledged subset of python3 that is still compatible with it, so that the transition is frictionless. At the same time, python4 should address some of the biggest limitations of python3:

  • the very low performance
  • the high memory overhead of default constructs
  • the GIL
  • the packaging mess

However, I don't think this can be fixed without breaking everything:

@c-cube
c-cube / .ocamlformat
Created May 15, 2019 19:11
.ocamlformat
profile=conventional
margin=80
if-then-else=fit-or-vertical
parens-ite=true
parens-tuple=multi-line-only
type-decl=sparse
space-around-collection-expressions=false
break-cases=toplevel
cases-exp-indent=2
leading-nested-match-parens=true
@c-cube
c-cube / radix_sort.rs
Created September 26, 2018 16:16
in place radix sort of 1 million u8 integers
extern crate rand;
const N : usize = 1_000_000;
//const N : usize = 20;
#[inline(always)]
fn test_bit(x: u8, bit: u8) -> bool {
(x & bit) != 0
}
@c-cube
c-cube / gen_coroutine.ml
Last active March 5, 2018 23:46
composable generators for `'a gen`
type 'a gen = unit -> 'a option
module Co : sig
type 'a t (* yields ['a] *)
val make : 'a t -> 'a gen
val return : 'a -> 'a t
@c-cube
c-cube / imandra_test.ml
Created January 29, 2018 17:19
imandra_test
let f l = l <> [(1, "foo"); (2, "bar")] ;;
@c-cube
c-cube / jbuild
Last active January 23, 2018 02:58
benchmark record vs object
(executable
((name truc)
(libraries (benchmark))
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -color always))
(ocamlopt_flags (:standard -O3 -bin-annot
-unbox-closures -unbox-closures-factor 20))
))
@c-cube
c-cube / fizbuzz.ml
Created December 15, 2017 12:56
fizbuzz using `sequence` in OCaml
Sequence.(1--100
|> map (fun n->n,if n mod 3=0 then "fiz" else "")
|> map (fun (n,s) -> n, if n mod 5=0 then s^"buzz" else s)
|> map (function (n,"") -> string_of_int n|(_,s) -> s)
|> iter print_endline);;
@c-cube
c-cube / term.ml
Created August 25, 2017 11:39
Efficient hashconsing in OCaml
type t = {
mutable id: int; (* unique ID *)
view: view;
}
and view =
| Const of string
| App of t * t
let equal t u = t.id = u.id
let hash t = Hashtbl.hash t.id
@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
@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 ->