Skip to content

Instantly share code, notes, and snippets.

View jozefg's full-sized avatar

daniel gratzer jozefg

View GitHub Profile
@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 / 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 / wat.idr
Last active August 29, 2015 14:17
Nonpositive tomfoolery in Idris
module wat
data Wat : Type where
foo : (Wat -> Wat) -> Wat
sapply : Wat -> Wat
sapply (foo x) = x (foo x)
u : Wat
u = sapply (foo (\x => sapply x))
@jozefg
jozefg / lheap.sml
Created February 28, 2015 22:30
Leftist priority queues in SML
signature KEY =
sig
type t
val compare : t * t -> order
end
signature PQUEUE =
sig
type t
type key
@jozefg
jozefg / unionfind.sml
Created February 22, 2015 23:34
Union Find with path compression and union-by-rank
signature UNION_FIND =
sig
type t
eqtype set
val new : t -> set
val union : set -> set -> unit
val repr : set -> set
val same : set -> set -> bool
end
@jozefg
jozefg / infer.sig
Last active February 9, 2022 11:59
A demonstration of type inference in SML
signature TYPEINFER =
sig
type tvar = int
datatype monotype = TBool
| TArr of monotype * monotype
| TVar of tvar
datatype polytype = PolyType of int list * monotype
datatype exp = True
| False
| Var of int
@jozefg
jozefg / ABT.hs
Created February 6, 2015 04:53
A tiny tottering implementation of abstract binding trees
{-# LANGUAGE DeriveFunctor, GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts, LambdaCase #-}
-- | A humane representation of binding.
module ABT ( FreeVar (..)
, Operator (..)
, ABT
, View (..)
, view
, fold
@jozefg
jozefg / queue.idr
Last active August 29, 2015 14:14
Queue in Idris
module queue
import Data.Vect
-- Here's the port of the Liquid Haskell blog post on amortized
-- queues. The tricksy bit is that the "amortized" bit depends on
-- laziness. This means that while in the REPL (where Idris is lazy)
-- this is reasonably efficient. It compiles absolutely horribly
-- though because each time push or pop something we rotate the whole
-- damned thing.
@jozefg
jozefg / pl.elf
Created January 24, 2015 18:11
A summary of the first two weeks of CMU's 15-312
nat : type.
s : nat -> nat.
z : nat.
bool : type.
true : bool.
false : bool.
plus : nat -> nat -> nat -> type.
%mode plus +N +M -R.
@jozefg
jozefg / Tail.hs
Created December 1, 2014 15:58
uncons without pattern matching
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE RankNTypes #-}
module Tail where
type CL a = forall c. (a -> c -> c) -> c -> c
t :: CL a -> (forall c. (a -> (Bool -> c) -> (Bool -> c))
-> (Bool -> c)
-> (Bool -> c))
t fold cons nil = fold myCons myNil