Skip to content

Instantly share code, notes, and snippets.

View keleshev's full-sized avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
let (>>) f g x = g (f x)
module Option = struct
let value ~default = function
| None -> default
| Some x -> x
end
module String = struct
include String
#!/usr/bin/env ruby
require "./rendertree"
require "./bin"
def compress(original)
tree = build_tree(original)
table = build_table(tree)
packer = BinPacker.new
module Tree = struct
type t =
| Node of {count: int; left: t; right: t}
| Leaf of {count: int; byte: char}
let count = function Node {count; _} | Leaf {count; _} -> count
let compare left right = Pervasives.compare (count left) (count right)
let rec nodes_to_tree nodes =
#!/usr/bin/env ocaml
let detect_sdk_version sdk_dir =
let include_ = sdk_dir </> "Include" in
Bin.ls include_ >>= fun dirs ->
let is_version dir = File.exist (include_ </> dir </> "um/Windows.h") in
Sh.filter dirs ~f:is_version >>= fun versions ->
Sh.head versions
module type Functor = sig
type 'a t
val map: ('a -> 'b) -> 'a t -> 'b t
end
module type Applicative = sig
type 'a t
(* Naive Levenshtein distance and the related diffing algorithm
$ ocaml levenshtein.ml
*)
let (=>) left right = print_char (if left = right then '.' else 'F')
module Levenshtein = struct
module Hashtbl = MoreLabels.Hashtbl
module Memoized = struct
let create ?(size=8) f =
let table = Hashtbl.create size in
fun argument ->
try Hashtbl.find table argument
with Not_found ->
let result = f argument in
module Int : sig
type t
(** Return None on overflow *)
val (+) : t -> t -> t option
val (-) : t -> t -> t option
val ( * ) : t -> t -> t option
(** Return None when divided by zero *)
val (/) : t -> t -> t option
module Id = struct
let (>>=) value callback =
callback value
let return x = x
let get x = x
end
@keleshev
keleshev / unimo.ml
Last active January 17, 2018 12:49
(* Paper: https://pdfs.semanticscholar.org/6485/84a9a714adc95a103c26d18b54c4aad1c812.pdf *)
module type EFFECT = sig
type 'unimo t
end
module Unimo (Effect : EFFECT) = struct