Skip to content

Instantly share code, notes, and snippets.

View jozefg's full-sized avatar

daniel gratzer jozefg

View GitHub Profile
@jozefg
jozefg / LambdaPi.hs
Last active August 29, 2015 14:10
type checker for λΠ
{-# LANGUAGE LambdaCase #-}
module LambdaPi where
import Control.Applicative hiding (Const)
import Control.Monad (guard)
import Control.Monad.Gen
import Control.Monad.Trans
import qualified Data.Map as M
data IExpr = Var Int
| App IExpr CExpr
@jozefg
jozefg / BoundPi.hs
Last active May 22, 2018 04:03
Bound my type checker for λΠ
{-# LANGUAGE LambdaCase, DeriveFunctor #-}
module LambdaPi where
import Bound
import Control.Applicative
import Control.Monad
import Control.Monad.Gen
import Control.Monad.Reader
import qualified Data.Map as M
import Data.Maybe
import Prelude.Extras
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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))