Skip to content

Instantly share code, notes, and snippets.

@aspiwack
aspiwack / Cdcl.hs
Last active September 28, 2023 06:42
Functional CDCL
module Cdcl where
import Data.Foldable
import Data.Maybe
import Data.Monoid
type Atom = Int
type Literal = (Bool, Atom)
@aspiwack
aspiwack / catlist.ml
Created June 17, 2022 14:55
An implementation of “programmed laziness” for list concatenation
module CatList : sig
(** “Lazy” lists with O(1) concatenation. *)
type +'a t
type (+'a, +'l) view =
| Nil
| Cons of 'a * 'l
val view : 'a t -> ('a, 'a t) view
@aspiwack
aspiwack / lhs2tex-mode.el
Created November 19, 2020 13:08
An Emacs configuration to colour Haskell code blocks in lhs2tex
;; I wrote a bit of Emacs configuration (which can be added to your
;; init.el) so that an lhs2tex file can be syntax-highlighted as a
;; Latex file but the Haskell code is highlighted as Haskell code. In
;; fact it's a little more than this, as the code blocks are
;; interpreted with the haskell-mode, so you can use your haskell
;; commands there.
;;
;; I don't recommend opening all `.lhs' file in this mode, as they
;; don't need to be Latex files. Literate Haskell is really agnostic
;; about its surrounding language.
@aspiwack
aspiwack / pipewire.org
Created May 9, 2021 15:52
Notes on Pipewire on Ubuntu in 2021-05

Replace Pulseaudio

Ubuntu 21.04 comes with Pipewire pre-installed. A pipewire service is running, but it’s doesn’t handle audio by default. For this you need to install a pipewire-pulse service. The (preinstalled) pipewire package provides such a service as documentation. First let’s copy it in Systemd’s space.

$ cp /usr/share/doc/pipewire/examples/systemd/user/pipewire-pulse.* /usr/lib/systemd/user/
@aspiwack
aspiwack / .merlin
Last active October 21, 2020 20:11
Heap: benchmarking pairing heaps vs braun trees
PKG core_bench
PKG qcheck
B _build
@aspiwack
aspiwack / gist:5090936
Created March 5, 2013 15:07
Circumventing OCaml's lack of empty pattern-matching cases when using gadts.
type void = { ex_falso : 'a.'a }
module Eq = struct
(** Leibniz equality. *)
type (_,_) t = Refl : ('a,'a) t
(** Variant of equality with a dummy case used to prove disequalities. *)
type (_,_) u = Refl' : ('a,'a) u | Dummy : void -> ('a,'b) u

Keybase proof

I hereby claim:

  • I am aspiwack on github.
  • I am aspiwack (https://keybase.io/aspiwack) on keybase.
  • I have a public key ASAdUTbPKE_sXn1PUR6IItRsYY6oaQki2LSvqSdZsCkntgo

To claim this, I am signing this object:

@aspiwack
aspiwack / stg.ml
Created December 12, 2016 07:59
A small STG-like lazy abstract machine
(** A small STG-like lazy abstract machine. What I take from the STG
is that constructors are responsible for choosing a branch in a
pattern-matching (the T in STG) and for updating themselves (by
pushing an update frame). Apart from that it's not very different
from a simple KAM. Note that the current implementation in GHC is
not actually tagless anymore, as it proved to be slower than a
tagged mechanism. But since it's a simpler design, (and the
difference doesn't matter much unless actual machine code is
emitted).
@aspiwack
aspiwack / wem.coq
Created January 2, 2016 20:49
A proof of ∀ A, A∨¬A explained with continuation
(** To give a direct proof of the constructive result that [forall
A:Prop, ~~(A\/~A)], it is useful to see [~A] as meaning a
"continuation of [A]". That is, [~A] is a computation that takes an
[A] and "returns".*)
(** Here is a first proof by forward chaining. *)
Lemma Proof₁ : forall A:Prop, ~~(A\/~A).
Proof.
intros A k₀.
(** We have [k₀:~(A\/~A)]. That is [k₀] is a continuation of either
@aspiwack
aspiwack / Horner.v
Last active December 30, 2015 06:09
A demonstration of the Derive plugin I wrote for Coq (commit 078efbe in Coq). It helps writing program derivation à la Richard Bird: starting with an executable specification transform it until it is efficient. Writing Derive f From spec Upto eq As h produces a goal |- eq spec ?57. At the end of the proof, two definitions are created f (transpar…
(** In this file we go a little further and follow the derivation
proposed by Jeremy Gibbons (
http://patternsinfp.wordpress.com/2011/05/05/horners-rule/ ). It
uses the definitions in Scan.v. The problem is to compute the
maximum sum of consecutive elements in a list [l]. It happens that
there is a linear time solution for that problem. Again, we start
with a simple executable specification, and using appropriate
rewriting steps, we find the linear time solution. *)
Require Import Prelim List NList Scan.