Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / gist:7ad4dafb6c39221fc773
Last active November 13, 2023 18:31
Lennart Augustsson's "Simpler, Easier!", copied (without permission) to get around the Great Fire Wall

Simpler, Easier!

Lennart Augustsson, Oct 25, 2007

In a recent paper, Simply Easy! (An Implementation of a Dependently Typed Lambda Calculus), the authors argue that type checking a dependently typed language is easy. I agree whole-heartedly, it doesn't have to be difficult at all. But I don't think the paper presents the easiest way to do it. So here is my take on how to write a simple dependent type checker. (There's nothing new here, and the authors of the paper are undoubtedly familiar with all of it.)

I'll start by implementing the untyped lambda calculus. It's a very simple language with just three constructs: variables, applications, and lambda expressions, i.e.,

@tel
tel / CBPV.hs
Last active August 29, 2015 14:12
Call by push value, actually
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE LambdaCase #-}
-- Code obviously based on <http://andrej.com/plzoo/html/levy.html>
module CBPV where
import Control.Applicative
import Control.Monad
@tel
tel / CBPV.hs
Last active August 29, 2015 14:12
PHOAS Call-by-push-value... Kind of!
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE LambdaCase #-}
-- Code obviously based on <http://andrej.com/plzoo/html/levy.html>
-- This is right now *not really* CBPV. In particular, the Rec binder
-- is both less well-behaved and far more complex than it ought to
-- be. Instead of passing a computation back (which should never be
-- possible as variables do not have computation types) it should pass
-- back a thunk.
@tel
tel / GettingToTesser.hs
Created January 3, 2015 03:21
Monadic Transducers with reduction
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
module Tesser where
import Control.Monad
import Data.Bifunctor
import Data.List (foldl')
@tel
tel / Tesser.hs
Created January 1, 2015 21:21
Tesseralike, but not there yet
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
module Tesser where
import Data.List (foldl')
import Data.Profunctor
import Data.Bifunctor
@tel
tel / Tesser.hs
Last active July 8, 2020 07:18
Not yet Tesser, but getting there
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
module Tesser where
import Data.List (foldl')
import Data.Profunctor
import Data.Bifunctor
@tel
tel / HetComp.hs
Created January 1, 2015 16:32
Really ugly Het Compose thing
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
module HetComp where
type family as ++ bs :: [k] where
@tel
tel / CPS.hs
Created January 1, 2015 00:53
CPS causes function composition to flip directions
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
type b <~ a = forall c . (b -> c) -> a -> c
back :: (a -> b) -> (b <~ a)
back f = (. f)
fwd :: (b <~ a) -> (a -> b)
fwd g = g id
@tel
tel / FreeCat.hs
Created December 31, 2014 22:12
FreeCat?
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
module FreeCat where
import Control.Category
import Prelude hiding ((.), id)
data Cat p a b where
Inj :: p a b -> Cat p a b
@tel
tel / Huff.hs
Created December 9, 2014 05:11
Huffman
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module Huff where