Skip to content

Instantly share code, notes, and snippets.

View jozefg's full-sized avatar

daniel gratzer jozefg

View GitHub Profile
@jozefg
jozefg / CoC.hs
Created March 27, 2015 04:52
A type checker for CoC (really any PTS)
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable, LambdaCase #-}
module CoC where
import Bound
import Control.Applicative
import Control.Monad
import Control.Monad.Gen
import Control.Monad.Trans
import Data.Foldable hiding (elem)
import qualified Data.Map as M
import Data.Maybe
@jozefg
jozefg / church-rosser.elf
Created April 30, 2015 20:06
Church Rosser... Right?
%{ Proving the Church Rosser theorem for lambda calculus in Twelf }%
%{ First, let's define the untyped lambda calculus }%
term : type.
ap : term -> term -> term.
lam : (term -> term) -> term.
%{ Evaluation }%
@jozefg
jozefg / Bracket.hs
Created May 3, 2015 00:19
A conversion from Lambda Calculus to SK calculus
module Bracket where
data Lam = Var Int | Ap Lam Lam | Lam Lam deriving Show
data SK = S | K | SKAp SK SK deriving Show
data SKH = Var' Int | S' | K' | SKAp' SKH SKH
-- Remove one variable
bracket :: SKH -> SKH
bracket (Var' 0) = SKAp' (SKAp' S' K') K'
@jozefg
jozefg / regex.agda
Created May 7, 2015 03:38
Regex matcher
module regex where
open import Data.Char using (Char; _≟_)
open import Data.List using (List ; _∷_ ; [])
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Data.Empty using (⊥)
-- Reason for this is because it simplifies pattern matching.
String : Set
String = List Char
@jozefg
jozefg / who-imports.py
Last active August 29, 2015 14:21
A quick script to plot which Haskell libs I import
#! /usr/bin/env python3
import os
import os.path as path
import re
import collections
from ascii_graph import Pyasciigraph
import sys
imports_re = re.compile('^import (qualified )?([a-z\.A-Z0-9]+)')
@jozefg
jozefg / general.agda
Created June 8, 2015 21:38
Fun with McBride's General monad
module general where
open import Function
import Data.Nat as N
import Data.Fin as F
import Data.Maybe as M
import Relation.Nullary as R
data General (S : Set)(T : S -> Set)(X : Set) : Set where
!! : X -> General S T X
_??_ : (s : S) -> (T s -> General S T X) -> General S T X
@jozefg
jozefg / binary.agda
Created June 12, 2015 14:06
Binary trees ala How To Keep Your Neighbors in Order
open import Level
open import Relation.Nullary
open import Relation.Binary
module binary (ord : DecTotalOrder zero zero zero) where
A = DecTotalOrder.Carrier ord
open DecTotalOrder {{...}}
module bound where
@jozefg
jozefg / j-to-j.agda
Created June 23, 2015 21:01
Deriving a nicer induction principle for equality
{-# OPTIONS --without-K #-}
module j-to-j where
open import Level
-- Gives rise to the annoying induction principle.
data _≡_ {A : Set} : A → A → Set where
refl : ∀ {a : A} → a ≡ a
-- Ignore the "Level" junk in here. It's needed because
-- we're trying to eliminate into a Set1 (U1 in Peter's
@jozefg
jozefg / conat.jonprl
Last active August 29, 2015 14:24
conats in JonPRL built from nats and \bigcap
Operator iterate : (0; 1; 0).
[iterate(N; F; B)] =def= [natrec(N; B; _.x.so_apply(F; x))].
Operator top : ().
[top] =def= [⋂(void; _.void)].
Theorem top-is-top :
[⋂(base; x.
⋂(base; y.
=(x; y; top)))] {
@jozefg
jozefg / russell.jonprl
Last active August 29, 2015 14:27
A proof that Type cannot be of type Type in JonPRL.
Operator Russell : ().
[Russell] =def= [{x : U{i} | not(member(x; x))}].
Tactic break-plus {
@{ [x : _ + _ |- _] => elim <x> }
}.
Theorem u-in-u-wf : [member(member(U{i}; U{i}); U{i'})] {
unfold <member>; eq-eq-base; unfold <bunion>; auto;
csubst [ceq(U{i}; lam(x.snd(x)) pair(inr(<>); U{i}))]