Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Lindig lindig

View GitHub Profile
View bible.mll
(*
* ocamllex bible.mll && ocamlopt -o bible bible.ml
* ./bible < bible.txt
*)
{
module L = Lexing
let get = L.lexeme
let sprintf = Printf.sprintf
@lindig
lindig / basic-module-design.md
Last active Apr 29, 2019
Basic considerations when creating a module in OCaml
View basic-module-design.md

Basic Module Design

First-In-First-Out Stack

module FIFO : sig
  exception Empty

  type 'a t

val empty: 'a t

View scan.mll
{
(* short names for important modules *)
module L = Lexing
module B = Buffer
type token =
| STR of string
| VAR of string
View size.rb
#! /usr/bin/env ruby
#
# Report code size by OCaml module in a native binary
#
require 'set'
require 'getoptlong'
class OCamlModule
include Comparable
View monads.ml
module type Monad = sig
type 'a t
val return: 'a -> 'a t
val bind: 'a t -> ('a -> 'b t) -> 'b t
end
View survey.tex
\documentclass[a4paper,12pt]{article}
\usepackage{fullpage}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage{xspace}
% PDF stuff
\ifx\pdfoutput\undefined
\else
\pdfpagewidth=210mm
View assoc_timing.ml
(*
* ocamlbuild -pkg unix assoc_timing.native
*
* When visiting all keys in an association list, when does it
* make sense to build a map first? According to this,
* building the map is amortised for list longer than 20 to 30
* elements.
*)
module Int = struct
@lindig
lindig / func.ml
Created Oct 7, 2016
OCaml Functors - small examples
View func.ml
==> func0.ml <==
module Debug = struct
let debug msg = Printf.eprintf "debug: %s\n" msg
let error msg = Printf.eprintf "error: %s\n" msg
end
let main () =
let argv = Array.to_list Sys.argv in
View mkdir.ml
(* Creating a directory with a given ownership and permissions looks
simple until you take closer look. Many things can fail: you might
not have the permissions to create or modify it, the desired groups
and owners might not exist.
This library tries to be systematic about it and de-composes the
complex operation (implemented in [mk]) into many small operations
that are stringed together in a monad: [>>=] sequences operations
and [//=] (read as: "or-else") recovers from a previous error.
@lindig
lindig / xs-dinghy.sh
Last active Sep 23, 2016
Run tests on XenServer by downloading and installing micro-kernel VM
View xs-dinghy.sh
#! /bin/sh
set -ex
VERSION="0.1.17"
GH="https://github.com/lindig"
VM="$GH/xen-test-vm/releases/download/$VERSION/test-vm.xen.gz"
KERNEL="xen-test-vm-${VERSION//./-}.xen.gz"
GUEST="/boot/guest"
IMG="$GUEST/$KERNEL"