Skip to content

Instantly share code, notes, and snippets.

View mafm's full-sized avatar

matthew mcdonald mafm

  • Western Australia
View GitHub Profile

Keybase proof

I hereby claim:

  • I am mafm on github.
  • I am mafm (https://keybase.io/mafm) on keybase.
  • I have a public key whose fingerprint is E400 C3AC EC79 56C3 D6FE 927A FA3B 8B70 4B38 F927

To claim this, I am signing this object:

@mafm
mafm / understanding-word-vectors.ipynb
Created March 3, 2018 05:02 — forked from aparrish/understanding-word-vectors.ipynb
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mafm
mafm / gadts.sml
Created June 13, 2018 17:02 — forked from bobatkey/gadts.sml
Encoding of GADTs in SML/NJ
(* This is a demonstration of the use of the SML module system to
encode (Generalized Algebraic Datatypes) GADTs via Church
encodings. The basic idea is to use the Church encoding of GADTs in
System Fomega and translate the System Fomega type into the module
system. As I demonstrate below, this allows things like the
singleton type of booleans, and the equality type, to be
represented.
This was inspired by Jon Sterling's blog post about encoding proofs
in the SML module system:
@mafm
mafm / peg.py
Created July 3, 2018 02:10 — forked from orlp/peg.py
PEG parser in Python.
from __future__ import unicode_literals
import sys
# We only use unicode in our parser, except for __repr__, which must return str.
if sys.version_info.major == 2:
repr_str = lambda s: s.encode("utf-8")
str = unicode
else:
repr_str = lambda s: s
@mafm
mafm / tetris.py
Created July 3, 2018 14:31 — forked from silvasur/tetris.py
Tetris implementation in Python
#!/usr/bin/env python2
#-*- coding: utf-8 -*-
# NOTE FOR WINDOWS USERS:
# You can download a "exefied" version of this game at:
# http://hi-im.laria.me/progs/tetris_py_exefied.zip
# If a DLL is missing or something like this, write an E-Mail ([email protected])
# or leave a comment on this gist.
# Very simple tetris implementation
@mafm
mafm / finalTagless.ml
Created July 17, 2018 16:19 — forked from lambdahands/finalTagless.ml
Final Tagless in OCaml
(*
* An OCaml implementation of final tagless, inspired from this article by Oleksandr Manzyuk:
* https://oleksandrmanzyuk.wordpress.com/2014/06/18/from-object-algebras-to-finally-tagless-interpreters-2/
*)
module FinalTagless = struct
type eval = { eval : int }
type view = { view : string }
module type ExpT = sig
@mafm
mafm / 90-min-scc.scm
Created July 17, 2018 17:58 — forked from nyuichi/90-min-scc.scm
The 90 Minute Scheme to C Compiler
#!/usr/local/Gambit-C/bin/gsi
; Copyright (C) 2004 by Marc Feeley, All Rights Reserved.
; This is the "90 minute Scheme to C compiler" presented at the
; Montreal Scheme/Lisp User Group on October 20, 2004.
; Usage with Gambit-C 4.0:
;
; % ./90-min-scc.scm test.scm
@mafm
mafm / fulcrum.v
Created October 25, 2018 00:52 — forked from bobatkey/fulcrum.v
Verification of a Fulcrum implementation against a reference implementation in Coq
Require Import List.
Require Import FunctionalExtensionality.
Require Import ZArith.
Require Import Zcompare.
(* c.f. https://twitter.com/Hillelogram/status/987432184217731073 *)
Set Implicit Arguments.
Lemma map_combine : forall A B C (f : A -> B) (g : A -> C) xs,
@mafm
mafm / Term.java
Created November 3, 2018 08:02 — forked from jbgi/Term.java
Generalized Algebraic Data Types (GADT) in Java
import static java.lang.System.*;
import java.util.function.BiFunction;
import java.util.function.Function;
// Implementation of a pseudo-GADT in Java, translating the examples from
// http://www.cs.ox.ac.uk/ralf.hinze/publications/With.pdf
// The technique presented below is, in fact, just an encoding of a normal Algebraic Data Type
// using a variation of the visitor pattern + the application of the Yoneda lemma to make it
// isomorphic to the targeted 'GADT'.
--Roughly based on https://github.com/Gabriel439/Haskell-Morte-Library/blob/master/src/Morte/Core.hs by Gabriel Gonzalez et al.
data Expr = Star | Box | Var Int | Lam Int Expr Expr | Pi Int Expr Expr | App Expr Expr deriving (Show, Eq)
subst v e (Var v') | v == v' = e
subst v e (Lam v' ta b ) | v == v' = Lam v' (subst v e ta) b
subst v e (Lam v' ta b ) = Lam v' (subst v e ta) (subst v e b )
subst v e (Pi v' ta tb) | v == v' = Pi v' (subst v e ta) tb
subst v e (Pi v' ta tb) = Pi v' (subst v e ta) (subst v e tb)
subst v e (App f a ) = App (subst v e f ) (subst v e a )