This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "./rendertree" | |
require "./bin" | |
def compress(original) | |
tree = build_tree(original) | |
table = build_table(tree) | |
packer = BinPacker.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type Functor = sig | |
type 'a t | |
val map: ('a -> 'b) -> 'a t -> 'b t | |
end | |
module type Applicative = sig | |
type 'a t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Id = struct | |
let (>>=) value callback = | |
callback value | |
let return x = x | |
let get x = x | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Paper: https://pdfs.semanticscholar.org/6485/84a9a714adc95a103c26d18b54c4aad1c812.pdf *) | |
module type EFFECT = sig | |
type 'unimo t | |
end | |
module Unimo (Effect : EFFECT) = struct |