Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
jtpaasch / Ocaml-Systems-Programming.md
Created July 5, 2018 14:28
Notes/tutorial on systems programming in OCaml.

OCaml Systems Programming

Including the unix module

To compile

Compile your modules first, e.g.:

@jtpaasch
jtpaasch / OCaml-Project-Layout.md
Created July 5, 2018 14:29
Notes/tutorial on a simple OCaml project scaffold.

OCaml Projects

Simple project

Create a folder called myutility, with a Makefile, as well as a src subfolder:

mkdir ~/myutility
@jtpaasch
jtpaasch / procstat.ml
Created July 9, 2018 21:08
A simple template for parsing /proc/[pid]/stat files (OCaml).
(* CLI =============================== *)
let pid_value = ref (-1)
let get_pid () = !pid_value
let check () =
match get_pid () with
| (-1) ->
Printf.printf "Error. Please provide a PID.\n%!";
exit 1
@jtpaasch
jtpaasch / software-foundations-lf-Basics.v
Created July 21, 2018 03:19
Software Foundations, Logical Foundations, Basics
(** * Basics: Functional Programming in Coq *)
(* REMINDER:
#####################################################
### PLEASE DO NOT DISTRIBUTE SOLUTIONS PUBLICLY ###
#####################################################
(See the [Preface] for why.)
*)
@jtpaasch
jtpaasch / software-foundations-lf-Lists.v
Created July 22, 2018 01:10
Software Foundations, Logical Foundations, Lists.v
(** * Lists: Working with Structured Data *)
Require Export Induction.
Module NatList.
(* ################################################################# *)
(** * Pairs of Numbers *)
(** In an [Inductive] type definition, each constructor can take
any number of arguments -- none (as with [true] and [O]), one (as
@jtpaasch
jtpaasch / software-foundations-lf-Induction.v
Last active July 22, 2018 23:16
Software Foundations, Logical Foundations, Induction.v
(** * Induction: Proof by Induction *)
(** Before getting started, we need to import all of our
definitions from the previous chapter: *)
Require Export Basics.
(** For the [Require Export] to work, you first need to use
[coqc] to compile [Basics.v] into [Basics.vo]. This is like
making a [.class] file from a [.java] file, or a [.o] file from a
@jtpaasch
jtpaasch / software-foundations-lf-Poly.v
Created July 22, 2018 23:15
Software Foundations, Logical Foundations, Poly.v
(** * Poly: Polymorphism and Higher-Order Functions *)
(* Final reminder: Please do not put solutions to the exercises in
publicly accessible places. Thank you!! *)
(* Suppress some annoying warnings from Coq: *)
Set Warnings "-notation-overridden,-parsing".
Require Export Lists.
(* ################################################################# *)
@jtpaasch
jtpaasch / coq-dockerfiles.md
Created July 24, 2018 15:48
Some old Coq Dockerfiles

Coq Dockerfiles

These are just experiments. Turns out the ocaml/opam docker containers only use a local copy of the opam repo, so opam update does nothing. Consequently, opam install coq.8.8.1 (for instance) would always say No such package. After I learned that I simply needed to add a remote opam repository to the docker container, regular opam install X started to work again, so my docker files got simpler.

I'm putting these here just to save them somewhere. There are little

@jtpaasch
jtpaasch / software-foundations-lf-Tactics.v
Created July 25, 2018 11:34
Software Foundations, Logical Foundations, Tactics.v
(** * Tactics: More Basic Tactics *)
(** This chapter introduces several additional proof strategies
and tactics that allow us to begin proving more interesting
properties of functional programs. We will see:
- how to use auxiliary lemmas in both "forward-style" and
"backward-style" proofs;
- how to reason about data constructors (in particular, how to use
the fact that they are injective and disjoint);
@jtpaasch
jtpaasch / Sequence_Tutorial_for_Jane_Street_Core.md
Created August 16, 2018 17:05
Tutorial/cheat sheet for using Jane Street Core's Sequences.

Sequence (from Jane Street Core)

Suppose you have a list.

let x = ["a"; "b"; "c"];;

Convert it to a sequence: